Sort an Array Alphabetically using the sort Method not working on FCC

Tell us what’s happening:

Not working on FFC

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/71.0.3578.98 Safari/537.36.

Link to the challenge:

Chrome changed the algorithm it uses for sort in about October, the solution that uses > is currently wrong for Chrome (and Chrome only I think), you can’t copy that answer and have it pass

Note that browsers just happened to allow this to work, that > solution doesn’t actually make a lot of sense if you look at what the callback function is supposed to return.

I would highly recommend reviewing the MDN docs about sorting. In this particular case, you may find that you’re making the lesson WAY more complicated than it has to be. Specifically, take a look at what the default sort mechanism employed by Array.sort() does.

Thank you guys, I got the answer both by implementing the right call back function and using the bare .sort() method as specified on mdn page :slight_smile:

1 Like

Now, how do I close this topic?

Either leave it as is, or select 1 of the answers above as a solution.