extra-array.web 3.0.115
Install from the command line:
Learn more about npm packages
$ npm install @nodef/extra-array.web@3.0.115
Install via package.json:
"@nodef/extra-array.web": "3.0.115"
About this version
An array is a collection of values, stored contiguously.
📦 NPM,
:smiley_cat: GitHub,
:running: RunKit,
:vhs: Asciinema,
:moon: Minified,
:scroll: Files,
:newspaper: JSDoc,
:blue_book: 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:
-
@extra-array/swap
: use rollup to bundle this es module. -
@extra-array/swap.min
: use in browser (browserify, uglify-js).
Stability: Experimental.
const array = require('extra-array');
// import * as array from "extra-array";
// import * as array from "https://unpkg.com/[email protected]/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 ]
// ]
Method | Action |
---|---|
is | Checks if value is array. |
get | Gets value at index. |
set | Sets value at index. |
swap | Exchanges two values. |
index | Gets zero-based index. |
indexRange | Gets index range of part of array. |
size | Counts the number of values. |
fill | Fills with given value. |
copy | Copies part of array to another. |
concat | Appends values from arrays. |
slice | Gets a part of array. |
splice | Removes or replaces existing values. |
flat | Flattens nested array to given depth. |
cut | Breaks array when test passes. |
chunk | Breaks array into chunks of given size. |
cycle | Gives values that cycle through array. |
repeat | Repeats an array given times. |
reverse | Reverses the array. |
rotate | Rotates values in array. |
interleave | Merges values from arrays. |
min | Finds smallest value. |
max | Finds largest entry. |
range | Finds smallest and largest entries. |
map | Updates values based on map function. |
filter | Keeps values which pass a test. |
count | Counts values which satisfy a test. |
partition | Segregates values by test result. |
group | Breaks array keeping similar values together. |
split | Breaks array considering test as separator. |
zip | Combines values from arrays. |
unique | Removes duplicate values. |
union | Gives values present in any array. |
intersection | Gives values present in both arrays. |
difference | Gives values of array not present in another. |
isUnique | Checks if there are no duplicate values. |
isDisjoint | Checks if arrays have no value in common. |
randomValue | Picks an arbitrary value. |
randomPrefix | Picks an arbitrary prefix. |
randomInfix | Picks an arbitrary infix. |
randomSuffix | Picks an arbitrary suffix. |
randomSubsequence | Picks an arbitrary subsequence. |
randomPermutation | Picks an arbitrary permutation. |
isEqual | Checks if two arrays are equal. |
compare | Compares two arrays. |
search | Finds index of first value passing a test. |
bsearch | Binary searches leftmost value in sorted array. |
find | Finds first value passing a test. |
findIndex | Finds index of leftmost value passing a test. |
sort | Arranges values in an order. |