npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

standings

2.0.0 • Public • Published

standings

Figure out 1st place, 2nd place, etc.

API

standings(items, rankBy)

items

Array of objects to rank.

rankBy

Can be either

  • string - Name of number property to rank items by.
  • function(item) - returns value to rank item by.

Returns

Array of objects where each object looks like

{
  item: <item from items parameter>,
  rank: number
}

The array is sorted in rank order (1, 2, 3, etc).

Example

var standings = require('standings');
 
var scores = [
  {score: 20, name: 'Amy'},
  {score: 30, name: 'Bob'},
  {score: 20, name: 'Chris'},
  {score: 10, name: 'Don'}
];
 
var rankings = standings(scores, 'score');

rankings looks like

[{
  item: {score: 30, name: 'Bob'},
  rank: 1
}, {
  item: {score: 20, name: 'Amy'},
  rank: 2
}, {
  item: {score: 20, name: 'Chris'},
  rank: 2
}, {
  item: {score: 10, name: 'Don'},
  rank: 4
}]

Install

npm install standings

License

MIT

install

npm i standings

Downloadsweekly downloads

11

version

2.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability