function reverseAlpha(arr) {
return arr.sort(function(a, b) {
return a === b ? 0 : a < b ? 1 : -1;
});
}
reverseAlpha(['l', 'h', 'z', 'b', 's']);
The code given in the lecture in step 17 of the “Functional Programming” (Sort an Array Alphabetically using the sort Method) course;
return a === b ...
Shouldn’t the line be resolved as I have indicated below?
function reverseAlpha(arr) {
return arr.sort(function(a, b) {
return a === b ? 0 : a < b ? -1 : 1;
});
}
Note: Your attention should be on -1 and 1.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Functional Programming - Sort an Array Alphabetically using the sort Method
Link to the challenge: