@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 search -
element
any The element to find -
compare
(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 compare -
b
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