Sort an Array Alphabetically using the sort Method: lambda expression not working

Tell us what’s happening:
I can’t figure out why this version of the solution with a lambda expression won’t work.


function alphabeticalOrder(arr) {
  // Add your code below this line
  
  return arr.sort((a,b)=> a>b);

  // Add your code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method

the callback needs to return a negative, positive number or zero

that way with greater than works only on some browsers

1 Like