Created
November 24, 2016 23:33
-
-
Save Hoxtygen/a3a8ef2a7d430af6c247ee657b7f8f24 to your computer and use it in GitHub Desktop.
How sorting works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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