Skip to content

Instantly share code, notes, and snippets.

@tomatau
Created March 26, 2017 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomatau/236d3068a9c35847837fa2ab9f8f56f9 to your computer and use it in GitHub Desktop.
Save tomatau/236d3068a9c35847837fa2ab9f8f56f9 to your computer and use it in GitHub Desktop.
Sort Arrays
import assert from 'assert'
const sortByAge = (source) => source.sort((itemA, itemB) => itemA.age - itemB.age)
const ob = (age) => ({ name: ''+age, age })
assert.deepEqual(
sortByAge([ ob(1), ob(6), ob(2), ob(5), ob(3), ob(4) ]),
[ ob(1), ob(2), ob(3), ob(4), ob(5), ob(6) ]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment