@bemoje/arr-sorted-has
v1.0.2
Published
Binary search -based indexOf for sorted arrays.
Downloads
5
Maintainers
Keywords
Readme
@bemoje/arr-sorted-has
Binary search -based indexOf for sorted arrays.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/arr-sorted-has
npm install --save @bemoje/arr-sorted-has
npm install --save-dev @bemoje/arr-sorted-has
Usage
import arrSortedHas from '@bemoje/arr-sorted-has'
const alpha = ['a', 'b', 'c']
arrSortedHas(alpha, 'b')
//=> true
arrSortedHas(alpha, 'e')
//=> false
const numeric = [2, 13, 20]
arrSortedHas(numeric, 20, {
numeric: true,
})
//=> true
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
Table of Contents
arrSortedHas
Binary search -based indexOf for sorted arrays.
Parameters
arr
Array The array to searchelement
any The element to findcompare
(comparator | object)?compare.numeric
boolean Sort numerically. Defaults to lexicographic/alphabetic sort. (optional, defaultfalse
)compare.descending
boolean Sort in descending order. Defaults to ascending order. (optional, defaultfalse
)compare.array
boolean Sort arrays. Nested arrays are also compared recursively. (optional, defaultfalse
)compare.by
(number | string | getter) Sort by either array index, a callback(element): any - or by object keys with dot-notation support. (optional, defaultundefined
)
Returns boolean
comparator
Type: Function
Parameters
a
any The first value to compareb
any The second value to compare
Returns number A negative number if a > b, a positive number if a < b, 0 otherwise.
getter
Type: Function
Parameters
a
any The value
Returns any The value to be compared