Can't do this. Can someone help?

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

Link to the challenge:

What have you tried? That might give is shims idea where you’re stuck…

i tried this

return arr.sort(function(a, b) {
    return a === b ? 0 : a < b ? 1 : -1;
  });

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

It’s simpler than you think. There is a JavaScript Method for it.

if you mean the sort method , that’s the topic of this challenge

Sorry, you’re right, i’m wrong.

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…

thanks guys i figured it out yesterday