Last active
August 29, 2015 13:56
-
-
Save bradoyler/9128629 to your computer and use it in GitHub Desktop.
JS console lesson : sorting numbers in Array : the functional nature of js
This file contains 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
// figure out how this works and why it's important | |
// array | |
var arr =[2,3,5,5,1,99,22,44]; | |
// sort ascending | |
arr.sort(function(n1,n2){ | |
return n1 - n2; | |
}); //output: [1, 2, 3, 5, 22, 44, 99] | |
console.log(arr); | |
// descending sort | |
arr.sort(function(n1,n2){ | |
return n2 - n1; | |
}) //output: [99, 44, 22, 5, 3, 2, 1] | |
console.log(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment