Sort an Array Alphabetically using the sort Method - Is That True

Tell us what’s happening:
Is that true? Please help me.

Your code so far


function alphabeticalOrder(arr) {
  // Add your code below this line
  return arr.sort(function(a,b) {
    return a > b;
  });
  
  // Add your code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.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/

[ 'a', 'a', 'c', 'd', 'g', 'z' ]

Solution works

A more compact way is to use the arrow function:

const alphabeticalOrder = arr => arr.sort((a,b) => a > b)

No. There is an error in this challenge (which has been fixed, but the update isn’t ready for release yet).
return a > b will work in Firefox because Firefox decided to implement the sort function in a non-standard way.

Neither of these solutions will work on Chrome. You need to use a compare function which returns -1 when a < b, 1 when a > b, and 0, when a = b.