Skip to content

Instantly share code, notes, and snippets.

@giolvani
Last active January 17, 2019 19:34
Show Gist options
  • Save giolvani/5ad07ad8ff12d91ad8af2942673e6326 to your computer and use it in GitHub Desktop.
Save giolvani/5ad07ad8ff12d91ad8af2942673e6326 to your computer and use it in GitHub Desktop.
Array helpers
// order by asc
itens.sort((a, b) => a.property - b.property);
// order by desc
itens.sort((a, b) => b.property - a.property);
const sum = itens.map(item => item.property).reduce((prev, next) => prev + next, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment