Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/zoubin/count-sorted
- Owner: zoubin
- Created: 2015-09-03T03:37:17.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-03T04:04:56.000Z (about 9 years ago)
- Last Synced: 2024-10-02T07:10:02.647Z (about 2 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
);```