Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created May 6, 2017 04:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alejandrolechuga/de8a0736a45ba64bc42523acd006dbc4 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/de8a0736a45ba64bc42523acd006dbc4 to your computer and use it in GitHub Desktop.
// sort
var pokemons = [
{ name:'pickachu', level: 50 } ,
{ name:'bulbasour', level: 10 } ,
{ name:'snorlax', level: 1 } ,
{ name:'mew', level: 2 } ,
{ name:'abra', level: 150 }
];
// var numbers = [2, 34, 10, 2, 5, 1];
console.log(pokemons.sort(function (prev, next) {
if (prev.name > next.name) {
return 1;
}
if (prev.name < next.name) {
return -1;
}
return 0;
// return prev.level - next.level;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment