Question: The code below is the answer given to sort an array in reverse Alphabetical order. I don’t understand what the “1” and “-1” represent respectively?
function reverseAlphabeticalOrder(arr) {
// Add your code below this line
return arr.sort(function(a, b) {
return a === b ? 0 : a < b ? 1 : -1;
});
// Add your code above this line
}
reverseAlphabeticalOrder(["l", "h", "z", "b", "s"]);
// Returns ['z', 's', 'l', 'h', 'b']
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.