rough-sortedness
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 = var sorted = 123456var unsorted = 123465console
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