Skip to content

Instantly share code, notes, and snippets.

@BuildWithLal
Last active April 18, 2018 05:25
Show Gist options
  • Save BuildWithLal/2c4c7390c631ab22e31fca3e82cae10d to your computer and use it in GitHub Desktop.
Save BuildWithLal/2c4c7390c631ab22e31fca3e82cae10d to your computer and use it in GitHub Desktop.
function sortByAge(a,b) {
if (a.age < b.age)
return -1;
if (a.age > b.age)
return 1;
return 0;
}
students = [{name: 'Axen', age: 12}, {name: 'Mike', age:10}, {name: 'John', age: 11}];
students.sort(sortByAge);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment