1.0.1 • Published 8 years ago

rankby v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

rankby

rankby is a tiny package that ranks arrays of objects in a decending manner. it handles ties even!

usage

npm install rankby

in your code, use rankby like this:

let rankedObject = rankby(object, key);

example with simple object

const rankby = require('rankby');

let simple = [{ score: 1 }, { score: 2 }, { score: 4 }, { score: 5 }];
simple = rankby(simple, 'score');
console.log(simple);
=> [{ score: 5, rank: 1 }, { score: 4, rank: 2 }, { score: 2, rank: 3 }, { score: 1, rank: 4 }]

example with ties

let ties = [{ score: 1 }, { score: 2 }, { score: 5 }, { score: 5 }];
ties = rankby(ties, 'score');
console.log(ties);
=> [{ score: 5, rank: 1 }, { score: 5, rank: 1 }, { score: 2, rank: 3 }, { score: 1, rank: 4 }]

license

MIT

1.0.1

8 years ago

1.0.0

8 years ago