@extra-array/search-value.min
npm i @extra-array/search-value.min

@extra-array/search-value.min

An array is a collection of values, stored contiguously.

by nodef

2.10.19 (see all)License:MITTypeScript:Built-In
npm i @extra-array/search-value.min
Readme

An array is a collection of values, stored contiguously.
📦 NPM, 😺 GitHub, 🏃‍♂️ RunKit, 📼 Asciinema, 🌔 Minified, 📜 Files, 📰 JSDoc, 📘 Wiki.

All functions except from*() take array as 1st parameter. Some methods accept a map function for faster comparision (like unique). I find the map-approach beautiful, which i learned from Haskell's sortOn(). You can notice that i have followed Javascript naming scheme as far as possible. Some names are borrowed from Haskell, Python, Java, Processing.

Methods look like:

  • swap(): doesn't modify the array itself (pure).
  • swap$(): modifies the array itself (update).

Methods as separate packages:

Stability: Experimental.


const array = require("extra-array");
// import * as array from "extra-array";
// import * as array from "https://unpkg.com/extra-array@2.10.15/index.mjs"; (deno)

var x = [1, 2, 3];
array.get(x, -1);
// 3

var x = [1, 2, 3, 4];
array.swap(x, 0, 1);
// [2, 1, 3, 4]

var x = [1, 2, 3, 4];
array.rotate(x, 1);
// [4, 1, 2, 3]

var x = [1, 3, 5, 7];
array.bsearch(x, 5);
// 2           ^ found

[...array.permutations([1, 2, 3])];
// [
//   [],          [ 1 ],
//   [ 2 ],       [ 3 ],
//   [ 1, 2 ],    [ 1, 3 ],
//   [ 2, 1 ],    [ 2, 3 ],
//   [ 3, 1 ],    [ 3, 2 ],
//   [ 1, 2, 3 ], [ 1, 3, 2 ],
//   [ 2, 1, 3 ], [ 2, 3, 1 ],
//   [ 3, 1, 2 ], [ 3, 2, 1 ]
// ]


Index

MethodAction
isChecks if value is array.
getGets value at index.
setSets value at index.
swapExchanges two values.
indexGets zero-based index.
indexRangeGets index range of part of array.
sizeCounts the number of values.
fillFills with given value.
copyCopies part of array to another.
concatAppends values from arrays.
sliceGets a part of array.
spliceRemoves or replaces existing values.
flatFlattens nested array to given depth.
cutBreaks array when test passes.
chunkBreaks array into chunks of given size.
cycleGives values that cycle through array.
repeatRepeats an array given times.
reverseReverses the array.
rotateRotates values in array.
interleaveMerges values from arrays.
minFinds smallest value.
maxFinds largest entry.
rangeFinds smallest and largest entries.
mapUpdates values based on map function.
filterKeeps values which pass a test.
countCounts values which satisfy a test.
partitionSegregates values by test result.
groupBreaks array keeping similar values together.
splitBreaks array considering test as separator.
zipCombines values from arrays.
uniqueRemoves duplicate values.
unionGives values present in any array.
intersectionGives values present in both arrays.
differenceGives values of array not present in another.
isUniqueChecks if there are no duplicate values.
isDisjointChecks if arrays have no value in common.
valuePicks an arbitrary value.
prefixPicks an arbitrary prefix.
infixPicks an arbitrary infix.
suffixPicks an arbitrary suffix.
subsequencePicks an arbitrary subsequence.
permutationPicks an arbitrary permutation.
isEqualChecks if two arrays are equal.
compareCompares two arrays.
searchFinds index of first value passing a test.
bsearchBinary searches leftmost value in sorted array.
findFinds first value passing a test.
findIndexFinds index of leftmost value passing a test.
sortArranges values in an order.


Downloads/wk

1

GitHub Stars

14

LAST COMMIT

3mos ago

MAINTAINERS

1

CONTRIBUTORS

3

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
2.10.19
latest
3mos ago
No alternatives found
No tutorials found
Add a tutorial