Tell us what’s happening:
Code isn’t working. I can’t understand what’s wrong here .
not Your code so far
function alphabeticalOrder(arr) {
// Add your code below this line
return arr.sort((a,b) => a > b);
// Add your code above this line
}
console.log(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/72.0.3626.121 Safari/537.36.
Try reading the documentation on the method
For example this seems interesting:
If compareFunction is not supplied, all non- undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order. For example, “banana” comes before “cherry”.
If you use a > b as return statement it depends on the browser if it works or not, now most don’t support this way of using the sort method
So you need to use a different way
Have you tried something different?
If you post your new code we can tell you how you are going
I got a code that works in my browser.
.
function alphabeticalOrder(arr){
// Add your code below this line
return arr.sort(function(a, b){
return a.localeCompare(b);
})
}
alphabeticalOrder([“a”, “d”, “c”, “A”, “z”, “g”]);
.