function alphabeticalOrder(arr) {
// Only change code below this line
// Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
function alphabeticalOrder(arr) {
// Only change code below this line
// Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13020.87.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.119 Safari/537.36.
Challenge: Sort an Array Alphabetically using the sort Method
if you want a before b you need to return a negative number for a < 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.
Good idea to read the documentation on the sort function, though. There is a default order, if no sort function is provided. Also, to my mind, the < or > to sort strings is iffy.
Is string.localeCompare(...) ever mentioned in the curriculum? I honestly can’t remember…