Not passing the challenge

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

I did everything right, but I can not pass the test.

My code:

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"]);

Results:

// running tests
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]) should return ["a", "a", "c", "d", "g", "z"].
alphabeticalOrder(["x", "h", "a", "m", "n", "m"]) should return ["a", "h", "m", "m", "n", "x"].
alphabeticalOrder(["a", "a", "a", "a", "x", "t"]) should return ["a", "a", "a", "a", "t", "x"].
// tests completed

Check MDN for:

I got stuck on this challenge some days ago, then somebody suggested me to simply sort this array without providing any of the call back function and it worked for me.

1 Like

The sort callback function should return a number, not a boolean.

1 Like

Do you mean to say that we need to convert each character of array into it’s equivalent ASCII value?

Not even remotely. You should read about the sort function and how the callback function works:

1 Like