persuasion
v1.0.1
Published
Wraps Array.sort to provide shortcuts to make sorting arrays that tiny bit less verbose
Downloads
24
Readme
persuasion
Wraps Array.sort to provide shortcuts to make sorting arrays that tiny bit less verbose
Installation
npm install persuasion
Basic Usage
var sort = require('persuasion')
sort([3,4,2,1,6]) //=> [1,2,3,4,6]
sort(['lol','rageguy','ateam','fry','troll']) //=> ['ateam','fry','lol','rageguy','troll']
Sort in reverse
Just add the config option reverse: true
sort([3,4,2,1,6], {reverse: true}) //=> [6,4,3,2,1]
Sort objects by property
Use the config option property to specify which property to sort by
var data = [
{ name: 'bob' },
{ name: 'tim' },
{ name: 'jim' },
{ name: 'ham' }
]
sort(data, {property: 'name'})
/*=>
[
{ name: 'bob' },
{ name: 'jim' },
{ name: 'ham' },
{ name: 'tim' }
]
*/