🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

rough-sortedness

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

rough-sortedness

Utility to compute the rough sortedness of a list

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

rough-sortedness stability

npm version build status test coverage downloads js-standard-style

Utility to compute the rough sortedness of a list.

Rough-Sortedness takes the ratio of the number of incrementing sequences in an array and divides it by the length of the total array to estimate the general sortedness of the array.

Warning: this rough sortedness metric is blind to interleaved sorted sequences, and reversed but perfectly sorted arrays will return a score of 0.

Usage

const roughSortedness = require('rough-sortedness')

var sorted = [1,2,3,4,5,6]
var unsorted = [1,2,3,4,6,5]
console.log(roughSortedness(sorted) > roughSortedness(unsorted))

API

roughSortedness

roughSortedness(arr, (a,b)=>{return a.value - b.value})

The function expects an array of items, and a comparator function. If no comparator function is provided, it will default to function defaultComparator (a, b) {return a - b}. The function returns a value from 0 to 1, where 1 is perfectly sorted, and 0 is impossibly unsorted.

Installation

$ npm install rough-sortedness

License

MIT

Keywords

sort

FAQs

Package last updated on 10 Apr 2017

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