Hi @castillorg !
It is always best to place your questions in the body of the topic.
You’ll get more responses that way.
This code right here should just be used for numbers
The reason being is that Javascript is a little funny when it comes to sorting numbers.
Let’s take this example array.
let arr = [3,100,24]
All the numbers are randomly sorted.
If I wanted to use the sort method for ascending order it would give me a funny result.
arr.sort()
//[ 100, 24, 3 ]
That obviously is not correct.
Javascript is looking at the first digit of each number. It only sees that 1 is less than 2. Not 100 and 24.
That is why you have to use this call back function.
arr.sort((a, b) => a - b)
The result would be this [ 3, 24, 100 ]
For this challenge, you can just use the sort method without a callback and it will pass.
You can also look at the FCC example and change it to fit the needs of the challenge to pass.
function reverseAlpha(arr) {
return arr.sort(function(a, b) {
return a === b ? 0 : a < b ? 1 : -1;
});
}
reverseAlpha(['l', 'h', 'z', 'b', 's']);
Hope that makes sense!