JSPM

  • Created
  • Published
  • Downloads 214794
  • Score
    100M100P100Q175682F
  • License Apache-2.0

Array / Arraylike utilities

Package Exports

  • @thi.ng/arrays

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/arrays) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@thi.ng/arrays

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Array / Arraylike utilities.

Status

STABLE - used in production

Installation

yarn add @thi.ng/arrays

Package sizes (gzipped): ESM: 1.3KB / CJS: 1.4KB / UMD: 1.4KB

Dependencies

API

Generated API docs

Binary search result predicates

The following predicates can be used to perform predecessor / successor queries using binarySearch().

  • bsLT() - Returns index of last item less than search value or -1 if no such values exist
  • bsLE() - Similar to bsLT(), but for less-than-equals queries
  • bsGT() - Returns index of first item greater than search value or -1 if no such values exist
  • bsGE() - Similar to bsGT(), but for less-than-equals queries
  • bsEQ() - Merely syntax sugar, casting any non-found result indices to -1
const src = [10, 20, 30, 40];

bsLT(binarySearch(src, 25))
// 1

// greater-than queries also require the array length

bsGT(binarySearch(src, 25), src.length)
// 2

bsGT(binarySearch(src, 40), src.length)
// -1

Authors

Karsten Schmidt

License

© 2018 - 2020 Karsten Schmidt // Apache Software License 2.0