Skip to content

Instantly share code, notes, and snippets.

@n0mad01
Created July 18, 2016 09:39
Show Gist options
  • Save n0mad01/04f4048ae2889080b2e01af1cfbf8115 to your computer and use it in GitHub Desktop.
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.
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