1.0.0 • Published 9 years ago
sort-array-by v1.0.0
sort-array-by
Takes an array and sorts it by the values returned from the given function.
install
$ npm install sort-array-byexample
const sortBy = require('sort-array-by')
sortBy(v => v.name, [
{ name: 'Andy', id: 1 },
{ name: 'Indy', id: 2 },
{ name: 'Jill', id: 3 },
{ name: 'Andy', id: 4 },
{ name: 'Jack', id: 5 }
])
/* => [
{ name: 'Andy', id: 1 },
{ name: 'Andy', id: 4 },
{ name: 'Indy', id: 2 },
{ name: 'Jack', id: 5 },
{ name: 'Jill', id: 3 }
] */api
sortBy(getValue, array)
getValue(item)iteman item from the array=> valuethe value to compare to determine sort order
arraythe array to sort=> arraya sorted array
1.0.0
9 years ago