Tell us what’s happening:
could someone break down and explain this return statement for me? I haven’t seen a good explanation for this syntax yet and I’m having trouble understanding it even though I used it to pass the test.
Your code so far
function alphabeticalOrder(arr) {
// Only change code below this line
return arr.sort(function(a, b) {
return a === b ? 0 : a > b ? 1 : -1;
})
// Only change 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/116.0.0.0 Safari/537.36
Challenge: Functional Programming - Sort an Array Alphabetically using the sort Method
Link to the challenge: