Sort an Array Alphabetically using the sort Method101118

Sort an Array Alphabetically using the sort Method101118
0

#1

Tell us what’s happening:

Your code so far


function alphabeticalOrder(arr) {
  return arr.sort(function(a,b) {
    return a>b;
  });
}
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/70.0.3538.77 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

@Ashish,
if you console.log the return value of that method, you’ll notice it does not actually sort the array. I recommended reading up on sort.


#3

Bro just use the simple sort method.

function alphabeticalOrder(arr) {
// Add your code below this line
return arr.sort();
// Add your code above this line
}
console.log(alphabeticalOrder([“a”, “d”, “c”, “a”, “z”, “g”]));