Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zoubin/count-sorted

Count the number of elements in a sorted collection less than, equal, or greater than the given value
https://github.com/zoubin/count-sorted

Last synced: 8 days ago
JSON representation

Count the number of elements in a sorted collection less than, equal, or greater than the given value

Awesome Lists containing this project

README

        

# count-sorted
Count the number of elements in a sorted collection less than, equal, or greater than the given value.

The collection should be either ascending or non-ascending.

## Example

```javascript
var equal = require('count-sorted/equal');
var less = require('count-sorted/less');
var greater = require('count-sorted/greater');

console.log(
equal([1, 1, 2, 2, 3, 3], 2) // 2
);

console.log(
less([1, 1, 2, 2, 3, 3], 2) // 2
);

console.log(
greater([1, 1, 2, 2, 3, 3], 2) // 2
);

console.log(
equal(
[{ x: 1 }, { x: 1 }, { x: 2 }, { x: 2 }, { x: 3 }, { x: 3 }],
{ x: 2 },
function (a, b) {
return a.x - b.x;
}
)
// 2
);

console.log(
less(
[{ x: 1 }, { x: 1 }, { x: 2 }, { x: 2 }, { x: 3 }, { x: 3 }],
{ x: 2 },
function (a, b) {
return a.x < b.x;
}
)
// 2
);

console.log(
greater(
[{ x: 1 }, { x: 1 }, { x: 2 }, { x: 2 }, { x: 3 }, { x: 3 }],
{ x: 2 },
function (a, b) {
return a.x > b.x;
}
)
// 2
);

```