1.0.1 • Published 5 years ago

@bemoje/arr-sorted-indexes-of v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@bemoje/arr-sorted-indexes-of

Find all indexes at which an array element exists, by binary search.

Version

Travis CI

Dependencies

Stats

Donate

Installation

npm install @bemoje/arr-sorted-indexes-of
npm install --save @bemoje/arr-sorted-indexes-of
npm install --save-dev @bemoje/arr-sorted-indexes-of

Usage

import arrSortedIndexesOf from '@bemoje/arr-sorted-indexes-of'

const alpha = ['a', 'b', 'b', 'c']

arrSortedIndexesOf(alpha, 'b')
//=> [1, 2]

const numeric = [0, 1, 1, 2]

arrSortedIndexesOf(alpha, 1, {
  numeric: true,
})
//=> [1, 2]

Tests

Uses Jest to test module functionality. Run tests to get coverage details.

npm run test

API

Table of Contents

arrSortedIndexesOf

Find all indexes at which an array element exists, by binary search.

Parameters
  • arr

  • element any The element to find

  • compare (comparator | object)?

    • compare.numeric boolean Sort numerically. Defaults to lexicographic/alphabetic sort. (optional, default false)

    • compare.descending boolean Sort in descending order. Defaults to ascending order. (optional, default false)

    • compare.array boolean Sort arrays. Nested arrays are also compared recursively. (optional, default false)

    • compare.by (number | string | getter) Sort by either array index, a callback(element): any - or by object keys with dot-notation support. (optional, default undefined)

Returns Array<number> Integer array of indexes

comparator

Comparator function callback definition.

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

Value-getter function callback definition.

Type: Function

Parameters
  • a any The value

Returns any The value to be compared