Code I am talking about: https://jsfiddle.net/sbe8yzv0/8/
I want to sort my array by the name with two buttons: First button sorts it by length and second buttons sorts it by alphabet.
When I sort by alphabet it doesn't want to function. It randomly puts the data in different positions. I have tried multiple ways of sorting it and they all act funky and doesn't sort it completely alphabetically. What can I do to make it actually sort the name in array by alphabet?
function sortNameAlphabetically(a, b) {
return a.name > b.name;
}
The sort by length is working as intended except when it sorts alpabeticly after length it does it bakwards. How do I make sure it sorts the right way?
function sortNameByLength(a, b) {
return b.name.length - a.name.length;
a.localeCompare(b);