Tell us what’s happening:
I don’t understand why this is not passing. The test cases are somehow failing here, although they are giving desired results when I am trying them out on my PC. Any help?
Your code so far
function alphabeticalOrder(arr) {
// Add your code below this line
return arr.sort(function(a,b) {
return a > b;
});
// Add your 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/76.0.3809.100 Safari/537.36.
It’s easy, and even though everything was alright with the code (as far as I can tell), It was simply not passing. I checked the hint, it was exactly the same as my code. I even tried copy-pasting the hint code, in order to bypass some flaw I might have been overlooking, but even that is not working. Any help?
PS : I even tried out the test cases that were failing somehow, and all of them gave the desired results on my end.
Almost identical to the one provided in the hints section
function alphabeticalOrder(arr) {
// Add your code below this line
return arr.sort(function(a,b) {
return a > b;
});
// Add your code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
Hmm I don’t know why the hint shows that. I would only compare the sort parameters if I’m dealing with numbers. But with letters, you can just simply call .sort(), as that will automatically sort out each letter alphabetically.
Lmao using sort with no callback function worked like a charm! Yes, the hint was weird. Made another post regarding a hint that was potentially outright wrong, but it did not gain much attention. Anyway, thanks
No problem! Yeah sometimes the hint can be a little strange… because if you compare if a > b and vice versa does not output the same result that the hint is giving. If you ever need to sort it from descending, you can call sort on the variable and then chain it with reverse.