[help me, I stuck with this in 3 weeks already] Sort an Array Alphabetically using the sort Method

[help me, I stuck with this in 3 weeks already] Sort an Array Alphabetically using the sort Method
0

#1

I’m really upset by what’s going on here.
I’ve been stuck by this in 3 weeks.
I strongly believe this is a one of the most important thing to pass to learn JS via Freecodecamp.
Million people walk through this but me.
And I still don’t know why and how and what to do.
I’m really upset about my self. And after 3 weeks stuck with this, I post here to hope some help can save me .

I really appreciate the kindness from heaven.

Your code so far


function alphabeticalOrder(arr) {
  return arr.sort(function(a, b) {
    return a > b;
  });
}


alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method/


#2

This code sorts arrays only alphabetically.

In case of numerical array a callback function needs to be passed but that’s off the topic.

**Here’s the code:- **

function alphabeticalOrder(arr) {
  
  return arr.sort();  //sort() arranges elements alphabetically
  
}
console.log(alphabeticalOrder(["a", "d", "c", "a", "z", "g"]));

// OUTPUT:-
// a,a,c,d,g,z


#3

Awesome, my savior!!!


#4

Sometimes some thing very easy can take a lot of time of thinking ,and yeah after that great effort you become so upset ,but you have to be sure that greatness is earned never awareded.
nice code bro.