Created
July 18, 2016 09:39
-
-
Save n0mad01/04f4048ae2889080b2e01af1cfbf8115 to your computer and use it in GitHub Desktop.
You have an array of objects in JavaScript. Each one contains a name (a string) and age (a number). Write a function which returns the objects ordered by age.
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
var arr = [{name: 'a', age: 234}, {name: 'b', age: 123}, {name: 'c', age: 122}] | |
arr.sort(function(a, b) { | |
return a.age - b.age; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment