Tell us what’s happening:
Can someone explain me step by step what is this line doing:
return a === b ? 0 : a < b ? -1 : 1;
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/83.0.4103.61 Safari/537.36.
Challenge: Sort an Array Alphabetically using the sort Method
Link to the challenge: