Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datarank

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datarank

datarank ========

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

datarank

Used to create simple tied ranks.

var Rank = require('datarank')

// Sample data
var data = [
    {id: 'a', value: 1}, 
    {id: 'b', value: 2}, 
    {id: 'c', value: 2}, 
    {id: 'd', value: 2}, 
    {id: 'e', value: 3}
  ]

// Examples
Rank(data, 'value').rank().normalize().value()     
// { data: (sorted data), rank: [0, .25, .5, .75, 1] }

Rank(data, 'value').rank().value()                 
// { data: (sorted data), rank: [0, 1, 2, 3, 4] }

Rank(data, 'value').tiedRank().normalize().value() 
// { data: (sorted data), rank: [0, .5, .5, .5, 1] }

Rank(data, 'value').tiedRank().value()             
// { data: (sorted data), rank: [0, 2, 2, 2, 4] }

Rank(data, 'value').tiedRank().value('merged')     
// [{id: 'a', value: 1, rank: 0}, {id: 'b', value: 2, rank: 2}, ... ] 

##Usage ####Rank(data, key, [direction]) Creates a new ranking object

  • data - an array of objects
  • key - the key to sort on
  • direction (optional) - -1 will invert the sort

####.rank() Perform a simple ranking

####.tiedRank() Average out rank of ties

####.normalize() Normalize ranks from 0 to 1

####.value([format]) Return the ranking

  • format (optional) - 'merged' will add the ranking to the data rows under the rank key

FAQs

Package last updated on 25 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc