https://github.com/shybyte/binary-search-by
NPM package for searching in sorted arrays fast and comfortable by a selector
https://github.com/shybyte/binary-search-by
Last synced: 11 months ago
JSON representation
NPM package for searching in sorted arrays fast and comfortable by a selector
- Host: GitHub
- URL: https://github.com/shybyte/binary-search-by
- Owner: shybyte
- License: mit
- Created: 2019-10-14T04:09:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T22:39:53.000Z (about 3 years ago)
- Last Synced: 2025-02-04T01:09:27.990Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 389 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# binary-search-by
[](https://travis-ci.org/shybyte/binary-search-by)
[](https://www.npmjs.com/package/binary-search-by)
[](https://codeclimate.com/github/shybyte/binary-search-by/maintainability)
[](https://codeclimate.com/github/shybyte/binary-search-by/test_coverage)
An NPM package for searching in sorted arrays fast and comfortable by a selector.
## Installation
[](https://www.npmjs.com/package/binary-search-by)
```bash
npm i binary-search-by
```
## Example
```javascript
import assert from 'assert';
import {binarySearchBy} from 'binary-search-by';
// Sorted by distance
const cities = [
{ distance: 0, name: 'Berlin' },
{ distance: 149, name: 'Leipzig' },
{ distance: 217, name: 'Jena' },
{ distance: 263, name: 'Wurzbach' }
];
const result1 = binarySearchBy(cities, 217, city => city.distance);
assert.deepEqual(result1, {found: true, index: 2});
const result2 = binarySearchBy(cities, 230, city => city.distance);
assert.deepEqual(result2, {found: false, index: 3});
```
## License
MIT
## Copyright
Copyright (c) 2019-present Marco Stahl