Sort an Array Alphabetically using the sort Method(Sorting)

Sort an Array Alphabetically using the sort Method(Sorting)
0

#1

Hi All,

I was trying to sort an array of letters alphabetically and my function does not pass any of the tests.
Any help would be appreciated.

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/67.0.3396.99 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


#2

try adding logs so you can understand why it doesn’t pass.
For eg. log the value of a-b before you return it. Does it give you what you thought it would?

(CTRL-SHIFT-J will show you the developer tools and console on Chrome browser so you can track your console.log statement outputs)


#4

[spoiler]

return arr.sort(function(a, b){
return a > b;
})

;[/spoiler]