Skip to content

Instantly share code, notes, and snippets.

@Hoxtygen
Created November 24, 2016 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hoxtygen/a3a8ef2a7d430af6c247ee657b7f8f24 to your computer and use it in GitHub Desktop.
Save Hoxtygen/a3a8ef2a7d430af6c247ee657b7f8f24 to your computer and use it in GitHub Desktop.
How sorting works
var myLove = ["the", "name", "of", "my", "love", "is", "yet", "unknown"];
var Array = [1, 7, 10, 40, 55, 16, 37, 85, 90, 100];
// This sort gives the default sorting
var newLove = myLove.sort();
// this sort gives a sorting whereby the first number comes first
var newArray = Array.sort(function(a, b) {
return a-b;
// however, if you want the largest number to come first then do b-a
//if you leave it like (a,b) it will be sorted numerically by default where 4 might come before 111 or 222
});
console.log(newLove);
console.log(newArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment