Tell us what’s happening:
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/74.0.3729.108 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/
console output
// 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
Desired results
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"]
.