Package Exports
- @thi.ng/arrays
- @thi.ng/arrays/api
- @thi.ng/arrays/arg-sort
- @thi.ng/arrays/binary-search
- @thi.ng/arrays/bisect
- @thi.ng/arrays/blit
- @thi.ng/arrays/ends-with
- @thi.ng/arrays/ensure-array
- @thi.ng/arrays/ensure-iterable
- @thi.ng/arrays/fill-range
- @thi.ng/arrays/find
- @thi.ng/arrays/floyd-rivest
- @thi.ng/arrays/fuzzy-match
- @thi.ng/arrays/insert
- @thi.ng/arrays/into
- @thi.ng/arrays/is-sorted
- @thi.ng/arrays/iterator
- @thi.ng/arrays/levenshtein
- @thi.ng/arrays/peek
- @thi.ng/arrays/quicksort
- @thi.ng/arrays/shuffle
- @thi.ng/arrays/sort-cached
- @thi.ng/arrays/starts-with
- @thi.ng/arrays/swap
- @thi.ng/arrays/swizzle
- @thi.ng/arrays/topo-sort
Readme
This project is part of the @thi.ng/umbrella monorepo.
About
Array / Arraylike utilities.
Status
STABLE - used in production
Search or submit any issues for this package
Installation
yarn add @thi.ng/arraysES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/arrays"></script>For Node.js REPL:
const arrays = await import("@thi.ng/arrays");Package sizes (brotli'd, pre-treeshake): ESM: 2.61 KB
Dependencies
API
- arrayIterator()
- argSort()
- binarySearch()
- bisect()
- blit1d() / blit2d()
- endsWith()
- ensureArray()
- ensureIterable()
- fillRange()
- find()
- floydRivest()
- fuzzyMatch()
- insert()
- into()
- isSorted()
- levenshtein()
- multiSwap()
- peek()
- quickSort()
- shuffle() (w/ custom PRNG support)
- shuffleRange() (w/ custom PRNG support)
- sortByCachedKey()
- startsWith()
- swap()
- swizzle()
- topoSort()
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 existbsLE()- Similar tobsLT(), but for less-than-equals queriesbsGT()- Returns index of first item greater than search value or -1 if no such values existbsGE()- Similar tobsGT(), but for less-than-equals queriesbsEQ()- 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)
// -1Authors
If this project contributes to an academic publication, please cite it as:
@misc{thing-arrays,
title = "@thi.ng/arrays",
author = "Karsten Schmidt",
note = "https://thi.ng/arrays",
year = 2018
}License
© 2018 - 2023 Karsten Schmidt // Apache License 2.0