extra-array
- Version 4.2.0
- Published
- 192 kB
- No dependencies
- MIT license
Install
npm i extra-array
yarn add extra-array
pnpm add extra-array
Overview
An array is a collection of values, stored contiguously.
Index
Functions
- accumulate()
- adjacentCombine()
- adjacentCombine$()
- allOf()
- anyOf()
- append()
- append$()
- at()
- back()
- cartesianProduct()
- chunk()
- clear$()
- clone()
- compare()
- concat()
- concat$()
- copy()
- copy$()
- copyWithin()
- copyWithin$()
- count()
- countAs()
- countEach()
- cut()
- cutAt()
- cutAtRight()
- cutRight()
- cycle()
- deepClone()
- difference()
- drop()
- dropRight()
- dropWhile()
- dropWhileRight()
- endsWith()
- entries()
- every()
- exclusiveScan()
- exclusiveScan$()
- fill()
- fill$()
- filter()
- filter$()
- filterAt()
- find()
- findAll()
- findIndex()
- findLastIndex()
- findRight()
- first()
- flat()
- flatMap()
- forEach()
- from()
- from$()
- fromApplication()
- fromApply()
- fromCall()
- fromInvocation()
- fromIterable()
- fromIterable$()
- fromRange()
- front()
- get()
- getAll()
- getPath()
- group()
- groupToMap()
- hasInfix()
- hasPath()
- hasPermutation()
- hasPrefix()
- hasSubsequence()
- hasSuffix()
- hasUnsortedValue()
- hasValue()
- head()
- ientries()
- iinfixes()
- ikeys()
- includes()
- inclusiveScan()
- inclusiveScan$()
- index()
- indexOf()
- indexRange()
- infix()
- infixes()
- init()
- interleave()
- intermix()
- interpolate()
- intersection()
- intersperse()
- ipermutations()
- iprefixes()
- is()
- isDisjoint()
- isEmpty()
- isEqual()
- isSorted()
- isubsequences()
- isuffixes()
- isUnique()
- ivalues()
- join()
- keys()
- last()
- lastIndexOf()
- left()
- length()
- map()
- map$()
- max()
- maxEntry()
- maximum()
- maximumEntries()
- maximumEntry()
- maximums()
- middle()
- min()
- minEntry()
- minimum()
- minimumEntries()
- minimumEntry()
- minimums()
- moveWithin()
- moveWithin$()
- partialSort()
- partialSort$()
- partition()
- partitionAs()
- partitionEach()
- permutation()
- permutation$()
- permutations()
- permute$()
- pop()
- pop$()
- popBack()
- popBack$()
- popFront()
- popFront$()
- prefix()
- prefixes()
- prepend()
- prepend$()
- push()
- push$()
- pushBack()
- pushBack$()
- pushFront()
- pushFront$()
- randomInfix()
- randomPermutation()
- randomPermutation$()
- randomPrefix()
- randomSubsequence()
- randomSuffix()
- randomValue()
- range()
- rangedPartialSort()
- rangedPartialSort$()
- rangedSort()
- rangedSort$()
- rangeEntries()
- reduce()
- reduceRight()
- reject()
- reject$()
- rejectAt()
- remove()
- remove$()
- removePath$()
- repeat()
- resize$()
- reverse()
- reverse$()
- right()
- rotate()
- rotate$()
- scanUntil()
- scanUntilRight()
- scanWhile()
- scanWhileRight()
- search()
- searchAdjacentDuplicate()
- searchAdjacentDuplicateValue()
- searchAll()
- searchInfix()
- searchInfixAll()
- searchInfixRight()
- searchMaximumValue()
- searchMaximumValues()
- searchMinimumValue()
- searchMinimumValues()
- searchMismatch()
- searchMismatchedValue()
- searchRight()
- searchSubsequence()
- searchUnsortedValue()
- searchValue()
- searchValueAll()
- searchValueRight()
- set()
- set$()
- setPath$()
- shallowClone()
- shift()
- shift$()
- shuffle$()
- size()
- slice()
- slice$()
- some()
- sort()
- sort$()
- splice()
- splice$()
- split()
- splitAt()
- startsWith()
- subsequence()
- subsequences()
- suffix()
- suffixes()
- swap()
- swap$()
- swapRanges()
- swapRanges$()
- symmetricDifference()
- tail()
- take()
- takeRight()
- takeWhile()
- takeWhileRight()
- toReversed()
- toSorted()
- toSpliced()
- union()
- union$()
- unique()
- unshift()
- unshift$()
- value()
- values()
- with()
- zip()
Type Aliases
Functions
function accumulate
accumulate: <T, U = T>( x: T[], fr: ReduceFunction<T, T | U>, acc?: T | U) => (T | U)[];
Perform inclusive prefix scan from left to right. [π](https://github.com/nodef/extra-array/wiki/inclusiveScan)
Parameter x
an array
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
[fr(acc, vβ), fr(fr(acc, vβ), vβ)...]
function adjacentCombine
adjacentCombine: <T>(x: T[], fc: CombineFunction<T>, acc: T) => T[];
Combine adjacent values of an array. [π](https://github.com/nodef/extra-array/wiki/adjacentCombine)
Parameter x
an array
Parameter fc
combine function (u, v)
Parameter acc
initial value
Returns
[fc(acc, vβ), fc(vβ, vβ)...] | vα΅’ β x
function adjacentCombine$
adjacentCombine$: <T>(x: T[], fc: CombineFunction<T>, acc: T) => T[];
Combine adjacent values of an array! [π](https://github.com/nodef/extra-array/wiki/adjacentCombine$)
Parameter x
an array (updated!)
Parameter fc
combine function (u, v)
Parameter acc
initial value
Returns
x = [fc(acc, vβ), fc(vβ, vβ)...] | vα΅’ β x
function allOf
allOf: <T>(x: T[], ft?: TestFunction<T> | null) => boolean;
Examine if all values satisfy a test. [π](https://github.com/nodef/extra-array/wiki/every)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
true if ft(vα΅’) = true for all vα΅’ β x
function anyOf
anyOf: <T>(x: T[], ft?: TestFunction<T> | null) => boolean;
Examine if any value satisfies a test. [π](https://github.com/nodef/extra-array/wiki/some)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
true if ft(vα΅’) = true for some vα΅’ β x
function append
append: <T>(x: T[], ...vs: T[]) => T[];
Add value to the end. [π](https://github.com/nodef/extra-array/wiki/push)
Parameter x
an array
Parameter vs
values to add
Returns
x β§Ί vs
function append$
append$: <T>(x: T[], ...vs: T[]) => T[];
Add values to the end! [π](https://github.com/nodef/extra-array/wiki/push$)
Parameter x
an array (updated!)
Parameter vs
values to add
Returns
x = x β§Ί vs
function at
at: <T>(x: T[], i: number) => T;
Get value at index. [π](https://github.com/nodef/extra-array/wiki/get)
Parameter x
an array
Parameter i
index
Returns
x[i]
function back
back: <T>(x: T[], vd?: T) => T;
Get last value. [π](https://github.com/nodef/extra-array/wiki/last)
Parameter x
an array
Parameter vd
default value
Returns
x[|x|-1] || vd
function cartesianProduct
cartesianProduct: <T, U = T>( xs: T[][], fm?: MapFunction<T[], T[] | U> | null) => (T[] | U)[];
Obtain cartesian product of arrays. [π](https://github.com/nodef/extra-array/wiki/cartesianProduct)
Parameter xs
arrays
Parameter fm
map function (vs, i)
Returns
xβ Γ xβ Γ ... = {[vβ, vβ, ...] | vβ β xβ, vβ β xβ, ...] }
function chunk
chunk: <T>(x: T[], n?: number, s?: number) => T[][];
Break array into chunks of given size. [π](https://github.com/nodef/extra-array/wiki/chunk)
Parameter x
an array
Parameter n
chunk size [1]
Parameter s
chunk step [n]
Returns
x[0..n] β§Ί x[s..s+n] β§Ί x[2s..2s+n] β§Ί ...
function clear$
clear$: <T>(x: T[]) => T[];
Remove all elements from an array! [π](https://github.com/nodef/extra-array/wiki/clear$)
Parameter x
an array (updated!)
Returns
cleared x
function clone
clone: <T>(x: T[]) => T[];
Shallow clone an array. [π](https://github.com/nodef/extra-array/wiki/shallowClone)
Parameter x
an array
Returns
shallow clone of x
function compare
compare: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Compare two arrays (lexicographically). [π](https://github.com/nodef/extra-array/wiki/compare)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x<y: -ve, x=y: 0, x>y: +ve
function concat
concat: <T>(...xs: T[][]) => T[];
Append values from arrays. [π](https://github.com/nodef/extra-array/wiki/concat)
Parameter xs
arrays
Returns
xβ β§Ί xβ β§Ί ... | [xβ, xβ, ...] = xs
function concat$
concat$: <T>(x: T[], ...ys: Iterable<T>[]) => T[];
Append values from arrays! [π](https://github.com/nodef/extra-array/wiki/concat$)
Parameter x
an array (updated!)
Parameter ys
arrays to append
Returns
x = x β§Ί yβ β§Ί yβ β§Ί ...] | [yβ, yβ, ...] = ys
function copy
copy: <T>(x: T[], y: T[], j?: number, i?: number, I?: number) => T[];
Copy part of array to another. [π](https://github.com/nodef/extra-array/wiki/copy)
Parameter x
target array
Parameter y
source array
Parameter j
write index [0]
Parameter i
read begin index [0]
Parameter I
read end index [|x|]
Returns
x[0..j] β§Ί y[i..I] β§Ί x[j+I-i..]
function copy$
copy$: <T>(x: T[], y: T[], j?: number, i?: number, I?: number) => T[];
Copy part of array to another! [π](https://github.com/nodef/extra-array/wiki/copy$)
Parameter x
target array (updated!)
Parameter y
source array
Parameter j
write index [0]
Parameter i
read begin index [0]
Parameter I
read end index [|x|]
Returns
x = x[0..j] β§Ί y[i..I] β§Ί x[j+I-i..]
function copyWithin
copyWithin: <T>(x: T[], j?: number, i?: number, I?: number) => T[];
Copy part of array within. [π](https://github.com/nodef/extra-array/wiki/copyWithin)
Parameter x
an array
Parameter j
write index [0]
Parameter i
read begin index [0]
Parameter I
read end index [|x|]
Returns
x[0..j] β§Ί x[i..I] β§Ί x[j+I-i..]
function copyWithin$
copyWithin$: <T>(x: T[], j?: number, i?: number, I?: number) => T[];
Copy part of array within! [π](https://github.com/nodef/extra-array/wiki/copyWithin$)
Parameter x
an array (updated!)
Parameter j
write index [0]
Parameter i
read begin index [0]
Parameter I
read end index [|x|]
Returns
x = x[0..j] β§Ί x[i..I] β§Ί x[j+I-i..]
function count
count: <T>(x: T[], ft: TestFunction<T>) => number;
Count values which satisfy a test. [π](https://github.com/nodef/extra-array/wiki/count)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
Ξ£tα΅’ | tα΅’ = 1 if ft(vα΅’) else 0; vα΅’ β x
function countAs
countAs: <T, U = T>( x: T[], fm?: MapFunction<T, T | U> | null) => Map<T | U, number>;
Count occurrences of each distinct value. [π](https://github.com/nodef/extra-array/wiki/countEach)
Parameter x
an array
Parameter fm
map function (v, i, x)
Returns
Map {value β count}
function countEach
countEach: <T, U = T>( x: T[], fm?: MapFunction<T, T | U> | null) => Map<T | U, number>;
Count occurrences of each distinct value. [π](https://github.com/nodef/extra-array/wiki/countEach)
Parameter x
an array
Parameter fm
map function (v, i, x)
Returns
Map {value β count}
function cut
cut: <T>(x: T[], ft: TestFunction<T>) => T[][];
Break array when test passes. [π](https://github.com/nodef/extra-array/wiki/cut)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[x[0..j], x[j..k], ...] | ft(x[i]) = true; i = j, k, ...
function cutAt
cutAt: <T>(x: T[], is: number[]) => T[][];
Break array at given indices. [π](https://github.com/nodef/extra-array/wiki/cutAt)
Parameter x
an array
Parameter is
split Β±indices (left to right)
Returns
[x[0..j], x[j..k], ...] | ft(x[i]) = true; i = j, k, ...; i β is
function cutAtRight
cutAtRight: <T>(x: T[], is: number[]) => T[][];
Break array after given indices. [π](https://github.com/nodef/extra-array/wiki/cutAtRight)
Parameter x
an array
Parameter is
split Β±indices (left to right)
Returns
[x[0..j+1], x[j+1..k], ...] | ft(x[i]) = true; i = j, k, ...; i β is
function cutRight
cutRight: <T>(x: T[], ft: TestFunction<T>) => T[][];
Break array after test passes. [π](https://github.com/nodef/extra-array/wiki/cutRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[x[0..j+1], x[j+1..k], ...] | ft(x[i]) = true; i = j, k, ...
function cycle
cycle: <T>(x: T[], i?: number, n?: number) => T[];
Obtain values that cycle through array. [π](https://github.com/nodef/extra-array/wiki/cycle)
Parameter x
an array
Parameter i
begin Β±index [0]
Parameter n
number of values [|x|]
function deepClone
deepClone: <T>(x: T[]) => T[];
Deep clone an array. [π](https://github.com/nodef/extra-array/wiki/deepClone)
Parameter x
an array
Returns
deep clone of x
function difference
difference: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Obtain values not present in another array. [π](https://github.com/nodef/extra-array/wiki/difference)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x - y = {v | v β x, v β y}
function drop
drop: <T>(x: T[], n?: number) => T[];
Discard first n values only. [π](https://github.com/nodef/extra-array/wiki/drop)
Parameter x
an array
Parameter n
number of values [1]
Returns
x[n..]
function dropRight
dropRight: <T>(x: T[], n?: number) => T[];
Discard last n values only. [π](https://github.com/nodef/extra-array/wiki/dropRight)
Parameter x
an array
Parameter n
number of values [1]
Returns
x[0..-n]
function dropWhile
dropWhile: <T>(x: T[], ft: TestFunction<T>) => T[];
Discard values from left, while a test passes. [π](https://github.com/nodef/extra-array/wiki/dropWhile)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
x[T..] | ft(x[i]) = true β i β [0, T-1] & ft(x[T]) = false
function dropWhileRight
dropWhileRight: <T>(x: T[], ft: TestFunction<T>) => T[];
Discard values from right, while a test passes. [π](https://github.com/nodef/extra-array/wiki/dropWhileRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
x[0..T-1] | ft(x[i]) = true β i β [T, |x|-1] & ft(x[T-1]) = false
function endsWith
endsWith: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array ends with a suffix. [π](https://github.com/nodef/extra-array/wiki/hasSuffix)
Parameter x
an array
Parameter y
search suffix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x[|x|-|y|..] = y?
function entries
entries: <T>(x: T[]) => Entries<T>;
Obtain all index-value pairs. [π](https://github.com/nodef/extra-array/wiki/entries)
Parameter x
an array
Returns
[[0, vβ], [1, vβ], ...] | vα΅’ = x[i]
function every
every: <T>(x: T[], ft?: TestFunction<T> | null) => boolean;
Examine if all values satisfy a test. [π](https://github.com/nodef/extra-array/wiki/every)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
true if ft(vα΅’) = true for all vα΅’ β x
function exclusiveScan
exclusiveScan: <T, U = T>( x: T[], fr: ReduceFunction<T, T | U>, acc: T | U) => (T | U)[];
Perform exclusive prefix scan from left to right. [π](https://github.com/nodef/extra-array/wiki/exclusiveScan)
Parameter x
an array
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
[acc, fr(acc, vβ), fr(fr(acc, vβ), vβ)...]
function exclusiveScan$
exclusiveScan$: <T>(x: T[], fr: ReduceFunction<T, T>, acc: T) => T[];
Perform exclusive prefix scan from left to right! [π](https://github.com/nodef/extra-array/wiki/exclusiveScan$)
Parameter x
an array (updated!)
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
x = [acc, fr(acc, vβ), fr(fr(acc, vβ), vβ)...]
function fill
fill: <T>(x: T[], v: T, i?: number, I?: number) => T[];
Fill with given value. [π](https://github.com/nodef/extra-array/wiki/fill)
Parameter x
an array
Parameter v
value
Parameter i
begin index [0]
Parameter I
end index [|x|]
Returns
x' | x' = x; x'[i..I] = v
function fill$
fill$: <T>(x: T[], v: T, i?: number, I?: number) => T[];
Fill with given value! [π](https://github.com/nodef/extra-array/wiki/fill$)
Parameter x
an array (updated!)
Parameter v
value
Parameter i
begin index [0]
Parameter I
end index [|x|]
Returns
x | x[i..I] = v
function filter
filter: <T>(x: T[], ft: TestFunction<T>) => T[];
Keep values which pass a test. [π](https://github.com/nodef/extra-array/wiki/filter)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[vβ, vβ, ...] | ft(vα΅’) = true; vα΅’ β x
function filter$
filter$: <T>(x: T[], ft: TestFunction<T>) => T[];
Keep values which pass a test! [π](https://github.com/nodef/extra-array/wiki/filter$)
Parameter x
an array (updated!)
Parameter ft
test function (v, i, x)
Returns
x = [vβ, vβ, ...] | ft(vα΅’) = true; vα΅’ β x
function filterAt
filterAt: <T>(x: T[], is: number[]) => T[];
Keep values at given indices. [π](https://github.com/nodef/extra-array/wiki/filterAt)
Parameter x
an array
Parameter is
indices
Returns
vβ, vβ, ... | vα΅’ = x[i]; i β is
function find
find: <T>(x: T[], ft: TestFunction<T>) => T;
Find first value passing a test. [π](https://github.com/nodef/extra-array/wiki/find)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first v | ft(v) = true; v β x
function findAll
findAll: <T>(x: T[], ft: TestFunction<T>) => T[];
Keep values which pass a test. [π](https://github.com/nodef/extra-array/wiki/filter)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[vβ, vβ, ...] | ft(vα΅’) = true; vα΅’ β x
function findIndex
findIndex: <T>(x: T[], ft: TestFunction<T>) => number;
Find index of first value passing a test. [π](https://github.com/nodef/extra-array/wiki/search)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first index of value, -1 if not found
function findLastIndex
findLastIndex: <T>(x: T[], ft: TestFunction<T>) => number;
Find index of last value passing a test. [π](https://github.com/nodef/extra-array/wiki/searchRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
last index of value, -1 if not found
function findRight
findRight: <T>(x: T[], ft: TestFunction<T>) => T;
Find last value passing a test. [π](https://github.com/nodef/extra-array/wiki/findRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
last v | ft(v) = true; v β x
function first
first: <T>(x: T[], vd?: T) => T;
Get first value. [π](https://github.com/nodef/extra-array/wiki/head)
Parameter x
an array
Parameter vd
default value
Returns
x[0] || vd
function flat
flat: ( x: any[], n?: number, fm?: MapFunction<any, any> | null, ft?: TestFunction<any> | null) => any[];
Flatten nested array to given depth. [π](https://github.com/nodef/extra-array/wiki/flat)
Parameter x
a nested array
Parameter n
maximum depth [-1 β all]
Parameter fm
map function (v, i, x)
Parameter ft
flatten test function (v, i, x) [is]
Returns
flat iterable
function flatMap
flatMap: ( x: any[], fm?: MapFunction<any, any> | null, ft?: TestFunction<any> | null) => any[];
Flatten nested array, based on map function. [π](https://github.com/nodef/extra-array/wiki/flatMap)
Parameter x
an array
Parameter fm
map function (v, i, x)
Parameter ft
flatten test function (v, i, x) [is]
Returns
flat iterable
function forEach
forEach: <T>(x: T[], fp: ProcessFunction<T>) => void;
Call a function for each value. [π](https://github.com/nodef/extra-array/wiki/forEach)
Parameter x
an array
Parameter fp
process function (v, i, x)
function from
from: <T>(x: Iterable<T>) => T[];
Convert an iterable to array. [π](https://github.com/nodef/extra-array/wiki/fromIterable)
Parameter x
an iterable
Returns
x as array
function from$
from$: <T>(x: Iterable<T>) => T[];
Convert an iterable to array! [π](https://github.com/nodef/extra-array/wiki/fromIterable$)
Parameter x
an iterable (updatable if array!)
Returns
x as array
function fromApplication
fromApplication: <T>(fm: MapFunction<T, T>, v: T, n: number) => T[];
Generate array from repeated function application. [π](https://github.com/nodef/extra-array/wiki/fromApplication)
Parameter fm
map function (v, i)
Parameter v
start value
Parameter n
number of values
Returns
[v, fm(v), fm(fm(v)), ...]
function fromApply
fromApply: <T>(fm: MapFunction<T, T>, v: T, n: number) => T[];
Generate array from repeated function application. [π](https://github.com/nodef/extra-array/wiki/fromApplication)
Parameter fm
map function (v, i)
Parameter v
start value
Parameter n
number of values
Returns
[v, fm(v), fm(fm(v)), ...]
function fromCall
fromCall: <T>(fn: Function, n: number) => T[];
Generate array from repeated function invocation. [π](https://github.com/nodef/extra-array/wiki/fromInvocation)
Parameter fn
function
Parameter n
number of values
Returns
[fn(), fn(), ...]
function fromInvocation
fromInvocation: <T>(fn: Function, n: number) => T[];
Generate array from repeated function invocation. [π](https://github.com/nodef/extra-array/wiki/fromInvocation)
Parameter fn
function
Parameter n
number of values
Returns
[fn(), fn(), ...]
function fromIterable
fromIterable: <T>(x: Iterable<T>) => T[];
Convert an iterable to array. [π](https://github.com/nodef/extra-array/wiki/fromIterable)
Parameter x
an iterable
Returns
x as array
function fromIterable$
fromIterable$: <T>(x: Iterable<T>) => T[];
Convert an iterable to array! [π](https://github.com/nodef/extra-array/wiki/fromIterable$)
Parameter x
an iterable (updatable if array!)
Returns
x as array
function fromRange
fromRange: (v: number, V: number, dv?: number) => number[];
Generate array from given number range. [π](https://github.com/nodef/extra-array/wiki/fromRange)
Parameter v
start number
Parameter V
end number, excluding
Parameter dv
step size [1]
Returns
[v, v+dv, v+2dv, ...]
function front
front: <T>(x: T[], vd?: T) => T;
Get first value. [π](https://github.com/nodef/extra-array/wiki/head)
Parameter x
an array
Parameter vd
default value
Returns
x[0] || vd
function get
get: <T>(x: T[], i: number) => T;
Get value at index. [π](https://github.com/nodef/extra-array/wiki/get)
Parameter x
an array
Parameter i
index
Returns
x[i]
function getAll
getAll: <T>(x: T[], is: number[]) => T[];
Get values at indices. [π](https://github.com/nodef/extra-array/wiki/getAll)
Parameter x
an array
Parameter is
indices
Returns
[x[iβ], x[iβ], ...] | [iβ, iβ, ...] = is
function getPath
getPath: (x: any[], p: number[]) => any;
Get value at path in a nested array. [π](https://github.com/nodef/extra-array/wiki/getPath)
Parameter x
a nested array
Parameter p
path
Returns
x[iβ][iβ][...] | [iβ, iβ, ...] = p
function group
group: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[][];
Keep similar values together and in order. [π](https://github.com/nodef/extra-array/wiki/group)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[x[0..k], x[k..l], ...] | fc(x[i], x[j]) = 0; i, j = 0..k / k..l / ...
function groupToMap
groupToMap: <T, U = T>( x: T[], fm?: MapFunction<T, T | U> | null) => Map<T | U, T[]>;
Segregate each distinct value. [π](https://github.com/nodef/extra-array/wiki/partitionEach)
Parameter x
an array
Parameter fm
map function (v, i, x)
Returns
Map {key β values}
function hasInfix
hasInfix: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array contains an infix. [π](https://github.com/nodef/extra-array/wiki/hasInfix)
Parameter x
an array
Parameter y
search infix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x[i..I] = y for some i, I?
function hasPath
hasPath: (x: any[], p: number[]) => boolean;
Check if nested array has a path. [π](https://github.com/nodef/extra-array/wiki/hasPath)
Parameter x
a nested array
Parameter p
path
Returns
x[iβ][iβ][...] exists? | [iβ, iβ, ...] = p
function hasPermutation
hasPermutation: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array has a permutation. [π](https://github.com/nodef/extra-array/wiki/hasPermutation)
Parameter x
an array
Parameter y
search permutation
Parameter fc
map function (v, i, x)
Parameter fm
compare function (a, b)
Returns
x contains a shuffled version of y?
function hasPrefix
hasPrefix: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array starts with a prefix. [π](https://github.com/nodef/extra-array/wiki/hasPrefix)
Parameter x
an array
Parameter y
search prefix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x[0..|y|] = y?
function hasSubsequence
hasSubsequence: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array has a subsequence. [π](https://github.com/nodef/extra-array/wiki/hasSubsequence)
Parameter x
an array
Parameter y
search subsequence
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x[iβ] β§Ί x[iβ] β§Ί ... = y, for some iβ, iβ, ...? | iβ < iβ < ...
function hasSuffix
hasSuffix: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array ends with a suffix. [π](https://github.com/nodef/extra-array/wiki/hasSuffix)
Parameter x
an array
Parameter y
search suffix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x[|x|-|y|..] = y?
function hasUnsortedValue
hasUnsortedValue: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array has an unsorted value. [π](https://github.com/nodef/extra-array/wiki/hasUnsortedValue)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x is not sorted?
function hasValue
hasValue: <T, U = T>( x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array has a value. [π](https://github.com/nodef/extra-array/wiki/hasValue)
Parameter x
an array
Parameter v
search value
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
v β x?
function head
head: <T>(x: T[], vd?: T) => T;
Get first value. [π](https://github.com/nodef/extra-array/wiki/head)
Parameter x
an array
Parameter vd
default value
Returns
x[0] || vd
function ientries
ientries: <T>(x: T[]) => IEntries<T>;
List all index-value pairs. [π](https://github.com/nodef/extra-array/wiki/ientries)
Parameter x
an array
Returns
[0, vβ], [1, vβ], ... | vα΅’ = x[i]
function iinfixes
iinfixes: <T>(x: T[], n?: number) => IterableIterator<T[]>;
List all possible infixes. [π](https://github.com/nodef/extra-array/wiki/iinfixes)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[], x[0..1], x[0..2], ..., x[1..2], ... if n<0; only of length n otherwise
function ikeys
ikeys: <T>(x: T[]) => IterableIterator<number>;
List all indices. [π](https://github.com/nodef/extra-array/wiki/ikeys)
Parameter x
an array
Returns
0, 1, ..., |x|-1
function includes
includes: <T>(x: T[], v: T, i?: number) => boolean;
Check if array has a value. [π](https://github.com/nodef/extra-array/wiki/includes)
Parameter x
an array
Parameter v
search value
Parameter i
begin index [0]
Returns
v β x[i..]?
function inclusiveScan
inclusiveScan: <T, U = T>( x: T[], fr: ReduceFunction<T, T | U>, acc?: T | U) => (T | U)[];
Perform inclusive prefix scan from left to right. [π](https://github.com/nodef/extra-array/wiki/inclusiveScan)
Parameter x
an array
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
[fr(acc, vβ), fr(fr(acc, vβ), vβ)...]
function inclusiveScan$
inclusiveScan$: <T>(x: T[], fr: ReduceFunction<T, T>, acc: T) => T[];
Perform inclusive prefix scan from left to right! [π](https://github.com/nodef/extra-array/wiki/inclusiveScan$)
Parameter x
an array (updated!)
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
x = [fr(acc, vβ), fr(fr(acc, vβ), vβ)...]
function index
index: <T>(x: T[], i: number) => number;
Get zero-based index for an element in array. [π](https://github.com/nodef/extra-array/wiki/index)
Parameter x
an array
Parameter i
Β±index
Returns
i' | x[i'] = x[i]; i' β [0, |x|]
function indexOf
indexOf: <T>(x: T[], v: T, i?: number) => number;
Find first index of a value. [π](https://github.com/nodef/extra-array/wiki/indexOf)
Parameter x
an array
Parameter v
search value
Parameter i
begin index [0]
Returns
index of v in x[i..] if found else -1
function indexRange
indexRange: <T>(x: T[], i?: number, I?: number) => [number, number];
Get zero-based index range for part of array. [π](https://github.com/nodef/extra-array/wiki/indexRange)
Parameter x
an array
Parameter i
begin Β±index [0]
Parameter I
end Β±index (exclusive) [|x|]
Returns
[i', I'] | i' β€ I'; i', I' β [0, |x|]
function infix
infix: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary infix. [π](https://github.com/nodef/extra-array/wiki/randomInfix)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[i..j] if n<0; x[i..i+n] otherwise | i, j β 0..|x|
function infixes
infixes: <T>(x: T[], n?: number) => T[][];
Obtain all possible infixes. [π](https://github.com/nodef/extra-array/wiki/infixes)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[[], x[0..1], x[0..2], ..., x[1..2], ...] if n<0; [only of length n] otherwise
function init
init: <T>(x: T[]) => T[];
Get values except last. [π](https://github.com/nodef/extra-array/wiki/init)
Parameter x
an array
Returns
x[0..|x|-1]
function interleave
interleave: <T>(xs: T[][]) => T[];
Place values from iterables alternately. [π](https://github.com/nodef/extra-array/wiki/interleave)
Parameter xs
arrays
Returns
[xβ[0], xβ[0], ..., xβ[1], xβ[0], ...] | [xβ, xβ, ...] = xs
function intermix
intermix: <T>( x: T[], y: T[], m?: number, n?: number, s?: number, t?: number) => T[];
Place values of an array between another. [π](https://github.com/nodef/extra-array/wiki/intermix)
Parameter x
an array
Parameter y
another array
Parameter m
number of values from x [1]
Parameter n
number of values from y [1]
Parameter s
step size for x [m]
Parameter t
step size for y [n]
Returns
x[0..m] β§Ί y[0..n] β§Ί x[s..s+m] β§Ί y[t..t+n] β§Ί ... β§Ί x[k*s..|x|-1] | k β W
function interpolate
interpolate: <T>(x: T[], fc: CombineFunction<T>) => T[];
Estimate new values between existing ones. [π](https://github.com/nodef/extra-array/wiki/interpolate)
Parameter x
an array
Parameter fc
combine function (a, b)
Returns
[x[0], fc(x[0], x[1]), x[1], fc(x[1], x[2]), ..., x[|x|-1]]
function intersection
intersection: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Obtain values present in both arrays. [π](https://github.com/nodef/extra-array/wiki/intersection)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x β© y = {v | v β x, v β y}
function intersperse
intersperse: <T>(x: T[], v: T) => T[];
Place a separator between every value. [π](https://github.com/nodef/extra-array/wiki/intersperse)
Parameter x
an array
Parameter v
separator
Returns
[x[0], v, x[1], v, ..., x[|x|-1]]
function ipermutations
ipermutations: <T>(x: T[], n?: number) => IterableIterator<T[]>;
List all possible permutations. [π](https://github.com/nodef/extra-array/wiki/ipermutations)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[], arrangements of length 1, of length 2, ... if n<0; only of length n otherwise
function iprefixes
iprefixes: <T>(x: T[], n?: number) => IterableIterator<T[]>;
List all possible prefixes. [π](https://github.com/nodef/extra-array/wiki/iprefixes)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[], x[..1], x[..2], ... if n<0; x[..n] otherwise
function is
is: (v: any) => v is any[];
Check if value is an array. [π](https://github.com/nodef/extra-array/wiki/is)
Parameter v
a value
Returns
v is an array?
function isDisjoint
isDisjoint: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if arrays have no value in common. [π](https://github.com/nodef/extra-array/wiki/isDisjoint)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x β© y = Ξ¦?
function isEmpty
isEmpty: <T>(x: T[]) => boolean;
Check if an array is empty. [π](https://github.com/nodef/extra-array/wiki/isEmpty)
Parameter x
an array
Returns
|x| = 0?
function isEqual
isEqual: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if two arrays are equal. [π](https://github.com/nodef/extra-array/wiki/isEqual)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x = y?
function isSorted
isSorted: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array is sorted. [π](https://github.com/nodef/extra-array/wiki/isSorted)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x is sorted?
function isubsequences
isubsequences: <T>(x: T[], n?: number) => IterableIterator<T[]>;
List all possible subsequences. [π](https://github.com/nodef/extra-array/wiki/isubsequences)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
elements selected by bit from 0..2^|x| if n<0; only of length n otherwise
function isuffixes
isuffixes: <T>(x: T[], n?: number) => IterableIterator<T[]>;
List all possible suffixes. [π](https://github.com/nodef/extra-array/wiki/isuffixes)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
x[0..], x[1..], x[2..], ... if n<0; x[-n..] otherwise
function isUnique
isUnique: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if there are no duplicate values. [π](https://github.com/nodef/extra-array/wiki/isUnique)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
β vα΅’, vβ±Ό β x, is vα΅’ β vβ±Ό?
function ivalues
ivalues: <T>(x: T[]) => IterableIterator<T>;
List all values. [π](https://github.com/nodef/extra-array/wiki/ivalues)
Parameter x
an array
Returns
vβ, vβ, ... | vα΅’ = x[i]
function join
join: <T>(x: T[], sep?: string) => string;
Join values together into a string. [π](https://github.com/nodef/extra-array/wiki/join)
Parameter x
an array
Parameter sep
separator [,]
Returns
"${vβ}${sep}${vβ}..." | vα΅’ β x
function keys
keys: <T>(x: T[]) => number[];
Obtain all indices. [π](https://github.com/nodef/extra-array/wiki/keys)
Parameter x
an array
Returns
[0, 1, ..., |x|-1]
function last
last: <T>(x: T[], vd?: T) => T;
Get last value. [π](https://github.com/nodef/extra-array/wiki/last)
Parameter x
an array
Parameter vd
default value
Returns
x[|x|-1] || vd
function lastIndexOf
lastIndexOf: <T>(x: T[], v: T, i?: number) => number;
Find last index of a value. [π](https://github.com/nodef/extra-array/wiki/lastIndexOf)
Parameter x
an array
Parameter v
search value
Parameter i
begin index [|x|-1]
Returns
last index of v in x[0..i] if found else -1
function left
left: <T>(x: T[], n?: number) => T[];
Keep first n values only. [π](https://github.com/nodef/extra-array/wiki/take)
Parameter x
an array
Parameter n
number of values [1]
Returns
x[0..n]
function length
length: <T>(x: T[], i?: number, I?: number) => number;
Find the length of an array. [π](https://github.com/nodef/extra-array/wiki/length)
Parameter x
an array
Parameter i
begin Β±index [0]
Parameter I
end Β±index (exclusive) [X]
Returns
|x[i..I]|
function map
map: <T, U = T>(x: T[], fm: MapFunction<T, T | U>) => (T | U)[];
Transform values of an array. [π](https://github.com/nodef/extra-array/wiki/map)
Parameter x
an array
Parameter fm
map function (v, i, x)
Returns
[fm(vβ), fm(vβ), ...] | vα΅’ β x
function map$
map$: <T>(x: T[], fm: MapFunction<T, T>) => T[];
Transform values of an array! [π](https://github.com/nodef/extra-array/wiki/map$)
Parameter x
an array (updated!)
Parameter fm
map function (v, i, x)
Returns
x = [fm(vβ), fm(vβ), ...]; vα΅’ β x
function max
max: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T;
Find first largest value. [π](https://github.com/nodef/extra-array/wiki/maximum)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
v | v β₯ vα΅’; vα΅’ β x
function maxEntry
maxEntry: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [number, T];
Find first largest entry. [π](https://github.com/nodef/extra-array/wiki/maximumEntry)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[max_index, max_value]
function maximum
maximum: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T;
Find first largest value. [π](https://github.com/nodef/extra-array/wiki/maximum)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
v | v β₯ vα΅’; vα΅’ β x
function maximumEntries
maximumEntries: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [number, T][];
Find largest entries. [π](https://github.com/nodef/extra-array/wiki/maximumEntries)
Parameter x
an array
Parameter n
number of values
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
n largest entries in descending order
function maximumEntry
maximumEntry: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [number, T];
Find first largest entry. [π](https://github.com/nodef/extra-array/wiki/maximumEntry)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[max_index, max_value]
function maximums
maximums: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Find largest values. [π](https://github.com/nodef/extra-array/wiki/maximums)
Parameter x
an array
Parameter n
number of values
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
n largest values in descending order
function middle
middle: <T>(x: T[], i: number, n?: number) => T[];
Get values from middle. [π](https://github.com/nodef/extra-array/wiki/middle)
Parameter x
an array
Parameter i
begin index
Parameter n
number of values [1]
Returns
x[i..i+n]
function min
min: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T;
Find first smallest value. [π](https://github.com/nodef/extra-array/wiki/minimum)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
v | v β€ vα΅’; vα΅’ β x
function minEntry
minEntry: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [number, T];
Find first smallest entry. [π](https://github.com/nodef/extra-array/wiki/minimumEntry)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[min_index, min_value]
function minimum
minimum: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T;
Find first smallest value. [π](https://github.com/nodef/extra-array/wiki/minimum)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
v | v β€ vα΅’; vα΅’ β x
function minimumEntries
minimumEntries: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [number, T][];
Find smallest entries. [π](https://github.com/nodef/extra-array/wiki/minimumEntries)
Parameter x
an array
Parameter n
number of values
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
n smallest entries in ascending order
function minimumEntry
minimumEntry: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [number, T];
Find first smallest entry. [π](https://github.com/nodef/extra-array/wiki/minimumEntry)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[min_index, min_value]
function minimums
minimums: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Find smallest values. [π](https://github.com/nodef/extra-array/wiki/minimums)
Parameter x
an array
Parameter n
number of values
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
n smallest values in ascending order
function moveWithin
moveWithin: <T>(x: T[], j?: number, i?: number, I?: number) => T[];
Move part of array within. [π](https://github.com/nodef/extra-array/wiki/moveWithin)
Parameter x
an array
Parameter j
write index [0]
Parameter i
read begin index [0]
Parameter I
read end index [|x|]
Returns
x[0..j] β§Ί x[i..I] β§Ί x[j..i] β§Ί x[I..]
function moveWithin$
moveWithin$: <T>(x: T[], j?: number, i?: number, I?: number) => T[];
Move part of array within! [π](https://github.com/nodef/extra-array/wiki/moveWithin$)
Parameter x
an array (updated!)
Parameter j
write Β±index [0]
Parameter i
read begin Β±index [0]
Parameter I
read end Β±index [|x|]
Returns
x = x[0..j] β§Ί x[i..I] β§Ί x[j..i] β§Ί x[I..]
function partialSort
partialSort: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Partially arrange values in order. [π](https://github.com/nodef/extra-array/wiki/partialSort)
Parameter x
an array
Parameter n
minimum number of values to sort
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x' | x' = x; x'[i] β€ x'[j] β i β€ j
function partialSort$
partialSort$: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Partially arrange values in order! [π](https://github.com/nodef/extra-array/wiki/partialSort$)
Parameter x
an array (updated!)
Parameter n
minimum number of values to sort
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x | x[i] β€ x[j] β i β€ j
function partition
partition: <T>(x: T[], ft: TestFunction<T>) => [T[], T[]];
Segregate values by test result. [π](https://github.com/nodef/extra-array/wiki/partition)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[satisfies, doesnt]
function partitionAs
partitionAs: <T, U = T>( x: T[], fm?: MapFunction<T, T | U> | null) => Map<T | U, T[]>;
Segregate each distinct value. [π](https://github.com/nodef/extra-array/wiki/partitionEach)
Parameter x
an array
Parameter fm
map function (v, i, x)
Returns
Map {key β values}
function partitionEach
partitionEach: <T, U = T>( x: T[], fm?: MapFunction<T, T | U> | null) => Map<T | U, T[]>;
Segregate each distinct value. [π](https://github.com/nodef/extra-array/wiki/partitionEach)
Parameter x
an array
Parameter fm
map function (v, i, x)
Returns
Map {key β values}
function permutation
permutation: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary permutation. [π](https://github.com/nodef/extra-array/wiki/randomPermutation)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x' | x' = x; values are randomly shuffled
function permutation$
permutation$: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary permutation! [π](https://github.com/nodef/extra-array/wiki/randomPermutation$)
Parameter x
an array (updated!)
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x | values are randomly shuffled
function permutations
permutations: <T>(x: T[], n?: number) => T[][];
Obtain all possible permutations. [π](https://github.com/nodef/extra-array/wiki/permutations)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[[], arrangements of length 1, of length 2, ...] if n<0; [only of length n] otherwise
function permute$
permute$: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary permutation! [π](https://github.com/nodef/extra-array/wiki/randomPermutation$)
Parameter x
an array (updated!)
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x | values are randomly shuffled
function pop
pop: <T>(x: T[]) => T[];
Remove last value. [π](https://github.com/nodef/extra-array/wiki/pop)
Parameter x
an array
Returns
x[0..|x|-1]
function pop$
pop$: <T>(x: T[]) => T[];
Remove last value! [π](https://github.com/nodef/extra-array/wiki/pop$)
Parameter x
an array (updated!)
Returns
x = x[0..|x|-1]
function popBack
popBack: <T>(x: T[]) => T[];
Remove last value. [π](https://github.com/nodef/extra-array/wiki/pop)
Parameter x
an array
Returns
x[0..|x|-1]
function popBack$
popBack$: <T>(x: T[]) => T[];
Remove last value. [π](https://github.com/nodef/extra-array/wiki/pop)
Parameter x
an array
Returns
x[0..|x|-1]
function popFront
popFront: <T>(x: T[]) => T[];
Remove first value. [π](https://github.com/nodef/extra-array/wiki/shift)
Parameter x
an array
Returns
x[1..]
function popFront$
popFront$: <T>(x: T[]) => T[];
Remove first value! [π](https://github.com/nodef/extra-array/wiki/shift$)
Parameter x
an array (updated!)
Returns
x = x[1..]
function prefix
prefix: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary prefix. [π](https://github.com/nodef/extra-array/wiki/randomPrefix)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[..i] if n<0; x[..n] otherwise | i β 0..|x|
function prefixes
prefixes: <T>(x: T[], n?: number) => T[][];
Obtain all possible prefixes. [π](https://github.com/nodef/extra-array/wiki/prefixes)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[[], x[..1], x[..2], ...] if n<0; [x[..n]] otherwise
function prepend
prepend: <T>(x: Iterable<T>, ...vs: T[]) => T[];
Add values to the start. [π](https://github.com/nodef/extra-array/wiki/unshift)
Parameter x
an array
Parameter vs
values to add
Returns
vs β§Ί x
function prepend$
prepend$: <T>(x: T[], ...vs: T[]) => T[];
Add values to the start! [π](https://github.com/nodef/extra-array/wiki/unshift$)
Parameter x
an array (updated!)
Parameter vs
values to add
Returns
x = vs β§Ί x
function push
push: <T>(x: T[], ...vs: T[]) => T[];
Add value to the end. [π](https://github.com/nodef/extra-array/wiki/push)
Parameter x
an array
Parameter vs
values to add
Returns
x β§Ί vs
function push$
push$: <T>(x: T[], ...vs: T[]) => T[];
Add values to the end! [π](https://github.com/nodef/extra-array/wiki/push$)
Parameter x
an array (updated!)
Parameter vs
values to add
Returns
x = x β§Ί vs
function pushBack
pushBack: <T>(x: T[], ...vs: T[]) => T[];
Add value to the end. [π](https://github.com/nodef/extra-array/wiki/push)
Parameter x
an array
Parameter vs
values to add
Returns
x β§Ί vs
function pushBack$
pushBack$: <T>(x: T[], ...vs: T[]) => T[];
Add values to the end! [π](https://github.com/nodef/extra-array/wiki/push$)
Parameter x
an array (updated!)
Parameter vs
values to add
Returns
x = x β§Ί vs
function pushFront
pushFront: <T>(x: Iterable<T>, ...vs: T[]) => T[];
Add values to the start. [π](https://github.com/nodef/extra-array/wiki/unshift)
Parameter x
an array
Parameter vs
values to add
Returns
vs β§Ί x
function pushFront$
pushFront$: <T>(x: T[], ...vs: T[]) => T[];
Add values to the start! [π](https://github.com/nodef/extra-array/wiki/unshift$)
Parameter x
an array (updated!)
Parameter vs
values to add
Returns
x = vs β§Ί x
function randomInfix
randomInfix: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary infix. [π](https://github.com/nodef/extra-array/wiki/randomInfix)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[i..j] if n<0; x[i..i+n] otherwise | i, j β 0..|x|
function randomPermutation
randomPermutation: <T>( x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary permutation. [π](https://github.com/nodef/extra-array/wiki/randomPermutation)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x' | x' = x; values are randomly shuffled
function randomPermutation$
randomPermutation$: <T>( x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary permutation! [π](https://github.com/nodef/extra-array/wiki/randomPermutation$)
Parameter x
an array (updated!)
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x | values are randomly shuffled
function randomPrefix
randomPrefix: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary prefix. [π](https://github.com/nodef/extra-array/wiki/randomPrefix)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[..i] if n<0; x[..n] otherwise | i β 0..|x|
function randomSubsequence
randomSubsequence: <T>( x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary subsequence. [π](https://github.com/nodef/extra-array/wiki/randomSubsequence)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[i, j, ...] | [i, j, ...] = is; |is| = |x| if n<0 else n
function randomSuffix
randomSuffix: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary suffix. [π](https://github.com/nodef/extra-array/wiki/randomSuffix)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[|x|-i..] if n<0; x[|x|-n..] otherwise | i β 0..|x|
function randomValue
randomValue: <T>(x: T[], fr?: ReadFunction<number> | null) => T;
Pick an arbitrary value. [π](https://github.com/nodef/extra-array/wiki/randomValue)
Parameter x
an array
Parameter fr
random number generator ([0, 1))
Returns
x[i] | i β 0..|x|
function range
range: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [T, T];
Find smallest and largest values. [π](https://github.com/nodef/extra-array/wiki/range)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[min_value, max_value]
function rangedPartialSort
rangedPartialSort: <T, U = T>( x: T[], i: number, I: number, n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Partially arrange a range of values in order. [π](https://github.com/nodef/extra-array/wiki/rangedPartialSort)
Parameter x
an array
Parameter i
begin index
Parameter I
end index (exclusive)
Parameter n
minimum number of values to sort
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x' | x' = x; x'[i] β€ x'[j] β i β€ j
function rangedPartialSort$
rangedPartialSort$: <T, U = T>( x: T[], i: number, I: number, n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Partially arrange a range of values in order! [π](https://github.com/nodef/extra-array/wiki/rangedPartialSort$)
Parameter x
an array (updated!)
Parameter i
begin index
Parameter I
end index (exclusive)
Parameter n
minimum number of values to sort
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x | x[i] β€ x[j] β i β€ j
function rangedSort
rangedSort: <T, U = T>( x: T[], i: number, I: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Arrange a range of values in order. [π](https://github.com/nodef/extra-array/wiki/rangedSort)
Parameter x
an array
Parameter i
begin index
Parameter I
end index (exclusive)
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x' | x' = x; x'[i] β€ x'[j] β i β€ j
function rangedSort$
rangedSort$: <T, U = T>( x: T[], i: number, I: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Arrange a range of values in order! [π](https://github.com/nodef/extra-array/wiki/rangedSort$)
Parameter x
an array (updated!)
Parameter i
begin index
Parameter I
end index (exclusive)
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x | x[i] β€ x[j] β i β€ j
function rangeEntries
rangeEntries: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => [[number, T], [number, T]];
Find smallest and largest entries. [π](https://github.com/nodef/extra-array/wiki/rangeEntries)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
[min_entry, max_entry]
function reduce
reduce: <T, U = T>(x: T[], fr: ReduceFunction<T, T | U>, acc?: T | U) => T | U;
Reduce values of array to a single value. [π](https://github.com/nodef/extra-array/wiki/reduce)
Parameter x
an array
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
fr(fr(acc, vβ), vβ)... | fr(acc, vβ) = vβ if acc not given
function reduceRight
reduceRight: <T, U = T>( x: T[], fr: ReduceFunction<T, T | U>, acc?: T | U) => T | U;
Reduce values from right, to a single value. [π](https://github.com/nodef/extra-array/wiki/reduceRight)
Parameter x
an array
Parameter fr
reduce function (acc, v, i, x)
Parameter acc
initial value
Returns
fr(fr(acc, vβββ), vβββ)... | fr(acc, vβββ) = vβββ if acc not given
function reject
reject: <T>(x: T[], ft: TestFunction<T>) => T[];
Discard values which pass a test. [π](https://github.com/nodef/extra-array/wiki/reject)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[vβ, vβ, ...] | ft(vα΅’) = false; vα΅’ β x
function reject$
reject$: <T>(x: T[], ft: TestFunction<T>) => T[];
Discard values which pass a test! [π](https://github.com/nodef/extra-array/wiki/reject$)
Parameter x
an array (updated!)
Parameter ft
test function (v, i, x)
Returns
x = [vβ, vβ, ...] | ft(vα΅’) = false; vα΅’ β x
function rejectAt
rejectAt: <T>(x: T[], is: number[]) => T[];
Discard values at given indices. [π](https://github.com/nodef/extra-array/wiki/rejectAt)
Parameter x
an array
Parameter is
indices
Returns
[vβ, vβ, ...] | vα΅’ = x[i]; i β is
function remove
remove: <T>(x: T[], i: number) => T[];
Remove value at index. [π](https://github.com/nodef/extra-array/wiki/remove)
Parameter x
an array
Parameter i
index
Returns
x[0..i] β§Ί x[i+1..]
function remove$
remove$: <T>(x: T[], i: number) => T[];
Remove value at index! [π](https://github.com/nodef/extra-array/wiki/remove$)
Parameter x
an array (updated!)
Parameter i
index
Returns
x \: [i]
function removePath$
removePath$: (x: any[], p: number[]) => any[];
Remove value at path in a nested array! [π](https://github.com/nodef/extra-array/wiki/removePath$)
Parameter x
a nested array (updated!)
Parameter p
path
Returns
x \: [iβ][iβ][...] | [iβ, iβ, ...] = p
function repeat
repeat: <T>(x: T[], n?: number) => T[];
Repeat an array given times. [π](https://github.com/nodef/extra-array/wiki/repeat)
Parameter x
an array
Parameter n
times [1]
Returns
x β§Ί x β§Ί ...(n times)
function resize$
resize$: <T>(x: T[], n: number, vd: T) => T[];
Resize an array to given length! [π](https://github.com/nodef/extra-array/wiki/resize$)
Parameter x
an array
Parameter n
new length
Parameter vd
default value
Returns
resized x
function reverse
reverse: <T>(x: T[]) => T[];
Reverse the values. [π](https://github.com/nodef/extra-array/wiki/reverse)
Parameter x
an array
Returns
[x[|x|-1], x[|x|-2], ..., x[1], x[0]]
function reverse$
reverse$: <T>(x: T[]) => T[];
Reverse the values! [π](https://github.com/nodef/extra-array/wiki/reverse$)
Parameter x
an array (updated!)
Returns
x = [x[|x|-1], x[|x|-2], ..., x[1], x[0]]
function right
right: <T>(x: T[], n?: number) => T[];
Keep last n values only. [π](https://github.com/nodef/extra-array/wiki/takeRight)
Parameter x
an array
Parameter n
number of values [1]
Returns
x[0..n]
function rotate
rotate: <T>(x: T[], n?: number) => T[];
Rotate values in array. [π](https://github.com/nodef/extra-array/wiki/rotate)
Parameter x
an array
Parameter n
rotate amount (+ve: left, -ve: right) [0]
Returns
x[n..] β§Ί x[0..n]
function rotate$
rotate$: <T>(x: T[], n?: number) => T[];
Rotate values in array! [π](https://github.com/nodef/extra-array/wiki/rotate$)
Parameter x
an array (updated!)
Parameter n
rotate amount (+ve: left, -ve: right) [0]
Returns
x = x[n..] β§Ί x[0..n]
function scanUntil
scanUntil: <T>(x: T[], ft: TestFunction<T>) => number;
Scan from left, until a test passes. [π](https://github.com/nodef/extra-array/wiki/scanUntil)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first index where test passes
function scanUntilRight
scanUntilRight: <T>(x: T[], ft: TestFunction<T>) => number;
Scan from right, until a test passes. [π](https://github.com/nodef/extra-array/wiki/scanUntilRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first index where test fails till end
function scanWhile
scanWhile: <T>(x: T[], ft: TestFunction<T>) => number;
Scan from left, while a test passes. [π](https://github.com/nodef/extra-array/wiki/scanWhile)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first index where test fails
function scanWhileRight
scanWhileRight: <T>(x: T[], ft: TestFunction<T>) => number;
Scan from right, while a test passes. [π](https://github.com/nodef/extra-array/wiki/scanWhileRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first index where test passes till end
function search
search: <T>(x: T[], ft: TestFunction<T>) => number;
Find index of first value passing a test. [π](https://github.com/nodef/extra-array/wiki/search)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
first index of value, -1 if not found
function searchAdjacentDuplicate
searchAdjacentDuplicate: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of an adjacent duplicate value. [π](https://github.com/nodef/extra-array/wiki/searchAdjacentDuplicateValue)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
index of first adjacent duplicate value, -1 if none
function searchAdjacentDuplicateValue
searchAdjacentDuplicateValue: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of an adjacent duplicate value. [π](https://github.com/nodef/extra-array/wiki/searchAdjacentDuplicateValue)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
index of first adjacent duplicate value, -1 if none
function searchAll
searchAll: <T>(x: T[], ft: TestFunction<T>) => number[];
Find indices of values passing a test. [π](https://github.com/nodef/extra-array/wiki/searchAll)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
indices of value
function searchInfix
searchInfix: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of an infix. [π](https://github.com/nodef/extra-array/wiki/searchInfix)
Parameter x
an array
Parameter y
search infix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first i | x[i..i+|y|] = y else -1
function searchInfixAll
searchInfixAll: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number[];
Find indices of an infix. [π](https://github.com/nodef/extra-array/wiki/searchInfixAll)
Parameter x
an array
Parameter y
search infix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
iβ, iβ, ... | x[j..j+|y|] = y; j β [iβ, iβ, ...]
function searchInfixRight
searchInfixRight: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find last index of an infix. [π](https://github.com/nodef/extra-array/wiki/searchInfixRight)
Parameter x
an array
Parameter y
search infix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first i | x[i..i+|y|] = y else -1
function searchMaximumValue
searchMaximumValue: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of maximum value. [π](https://github.com/nodef/extra-array/wiki/searchMaximumValue)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first index of maximum value, -1 if empty
function searchMaximumValues
searchMaximumValues: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number[];
Find indices of maximum values. [π](https://github.com/nodef/extra-array/wiki/searchMaximumValues)
Parameter x
an array
Parameter n
number of values
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
indices of maximum values in descending order
function searchMinimumValue
searchMinimumValue: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of minimum value. [π](https://github.com/nodef/extra-array/wiki/searchMinimumValue)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first index of minimum value, -1 if empty
function searchMinimumValues
searchMinimumValues: <T, U = T>( x: T[], n: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number[];
Find indices of minimum values. [π](https://github.com/nodef/extra-array/wiki/searchMinimumValues)
Parameter x
an array
Parameter n
number of values
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
indices of minimum values in ascending order
function searchMismatch
searchMismatch: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index where two arrays differ. [π](https://github.com/nodef/extra-array/wiki/searchMismatchedValue)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first index where x[i] β y[i], or -1
function searchMismatchedValue
searchMismatchedValue: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index where two arrays differ. [π](https://github.com/nodef/extra-array/wiki/searchMismatchedValue)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first index where x[i] β y[i], or -1
function searchRight
searchRight: <T>(x: T[], ft: TestFunction<T>) => number;
Find index of last value passing a test. [π](https://github.com/nodef/extra-array/wiki/searchRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
last index of value, -1 if not found
function searchSubsequence
searchSubsequence: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of a subsequence. [π](https://github.com/nodef/extra-array/wiki/searchSubsequence)
Parameter x
an array
Parameter y
search subsequence
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
begin index of subsequence, -1 if not found
function searchUnsortedValue
searchUnsortedValue: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of an unsorted value. [π](https://github.com/nodef/extra-array/wiki/searchUnsortedValue)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
index of first unsorted value, -1 if sorted
function searchValue
searchValue: <T, U = T>( x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find first index of a value. [π](https://github.com/nodef/extra-array/wiki/searchValue)
Parameter x
an array
Parameter v
search value
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
first index of value, -1 if not found
function searchValueAll
searchValueAll: <T, U = T>( x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number[];
Find indices of value. [π](https://github.com/nodef/extra-array/wiki/searchValueAll)
Parameter x
an array
Parameter v
search value
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
indices of value
function searchValueRight
searchValueRight: <T, U = T>( x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => number;
Find last index of a value. [π](https://github.com/nodef/extra-array/wiki/searchValueRight)
Parameter x
an array
Parameter v
search value
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
last index of value, -1 if not found
function set
set: <T>(x: T[], i: number, v: T) => T[];
Set value at index. [π](https://github.com/nodef/extra-array/wiki/set)
Parameter x
an array
Parameter i
index
Parameter v
value
Returns
x' | x' = x; x'[i] = v
function set$
set$: <T>(x: T[], i: number, v: T) => T[];
Set value at index! [π](https://github.com/nodef/extra-array/wiki/set$)
Parameter x
an array (updated!)
Parameter i
index
Parameter v
value
Returns
x | x[i] = v
function setPath$
setPath$: (x: any[], p: number[], v: any) => any[];
Set value at path in a nested array! [π](https://github.com/nodef/extra-array/wiki/setPath$)
Parameter x
a nested array (updated!)
Parameter p
path
Parameter v
value
Returns
x | x[iβ][iβ][...] = v; [iβ, iβ, ...] = p
function shallowClone
shallowClone: <T>(x: T[]) => T[];
Shallow clone an array. [π](https://github.com/nodef/extra-array/wiki/shallowClone)
Parameter x
an array
Returns
shallow clone of x
function shift
shift: <T>(x: T[]) => T[];
Remove first value. [π](https://github.com/nodef/extra-array/wiki/shift)
Parameter x
an array
Returns
x[1..]
function shift$
shift$: <T>(x: T[]) => T[];
Remove first value! [π](https://github.com/nodef/extra-array/wiki/shift$)
Parameter x
an array (updated!)
Returns
x = x[1..]
function shuffle$
shuffle$: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary permutation! [π](https://github.com/nodef/extra-array/wiki/randomPermutation$)
Parameter x
an array (updated!)
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x | values are randomly shuffled
function size
size: <T>(x: T[], i?: number, I?: number) => number;
Find the length of an array. [π](https://github.com/nodef/extra-array/wiki/length)
Parameter x
an array
Parameter i
begin Β±index [0]
Parameter I
end Β±index (exclusive) [X]
Returns
|x[i..I]|
function slice
slice: <T>(x: T[], i?: number, I?: number) => T[];
Get part of an array. [π](https://github.com/nodef/extra-array/wiki/slice)
Parameter x
an array
Parameter i
begin index [0]
Parameter I
end index [|x|]
Returns
x[i..I]
function slice$
slice$: <T>(x: T[], i?: number, I?: number) => T[];
Get part of an array! [π](https://github.com/nodef/extra-array/wiki/slice$)
Parameter x
an array (updated!)
Parameter i
begin index [0]
Parameter I
end index [|x|]
Returns
x = x[i..I]
function some
some: <T>(x: T[], ft?: TestFunction<T> | null) => boolean;
Examine if any value satisfies a test. [π](https://github.com/nodef/extra-array/wiki/some)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
true if ft(vα΅’) = true for some vα΅’ β x
function sort
sort: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Arrange values in order. [π](https://github.com/nodef/extra-array/wiki/sort)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x' | x' = x; x'[i] β€ x'[j] β i β€ j
function sort$
sort$: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Arrange values in order! [π](https://github.com/nodef/extra-array/wiki/sort$)
Parameter x
an array (updated!)
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x | x[i] β€ x[j] β i β€ j
function splice
splice: <T>(x: T[], i: number, n?: number, ...vs: T[]) => T[];
Remove or replace existing values. [π](https://github.com/nodef/extra-array/wiki/splice)
Parameter x
an array
Parameter i
remove Β±index
Parameter n
number of values to remove [rest]
Parameter vs
values to insert
Returns
x[0..i] β§Ί vs β§Ί x[i+n..]
function splice$
splice$: <T>(x: T[], i: number, n?: number, ...vs: T[]) => T[];
Remove or replace existing values! [π](https://github.com/nodef/extra-array/wiki/splice$)
Parameter x
an array (updated!)
Parameter i
remove Β±index
Parameter n
number of values to remove [rest]
Parameter vs
values to insert
Returns
x = x[0..i] β§Ί vs β§Ί x[i+n..]
function split
split: <T>(x: T[], ft: TestFunction<T>) => T[][];
Break array considering test as separator. [π](https://github.com/nodef/extra-array/wiki/split)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
[x[j..k], x[l..m], ...] | ft(x[i]) = true; i = 0..j / k..l / ...
function splitAt
splitAt: <T>(x: T[], is: number[]) => T[][];
Break array considering indices as separator. [π](https://github.com/nodef/extra-array/wiki/splitAt)
Parameter x
an array
Parameter is
indices (sorted)
Returns
[x[j..k], x[l..m], ...] | ft(x[i]) = true; i = 0..j / k..l / ...; i β is
function startsWith
startsWith: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => boolean;
Examine if array starts with a prefix. [π](https://github.com/nodef/extra-array/wiki/hasPrefix)
Parameter x
an array
Parameter y
search prefix
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x[0..|y|] = y?
function subsequence
subsequence: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary subsequence. [π](https://github.com/nodef/extra-array/wiki/randomSubsequence)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[i, j, ...] | [i, j, ...] = is; |is| = |x| if n<0 else n
function subsequences
subsequences: <T>(x: T[], n?: number) => T[][];
Obtain all possible subsequences. [π](https://github.com/nodef/extra-array/wiki/subsequences)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[elements selected by bit from 0..2^|x|] if n<0; [only of length n] otherwise
function suffix
suffix: <T>(x: T[], n?: number, fr?: ReadFunction<number> | null) => T[];
Pick an arbitrary suffix. [π](https://github.com/nodef/extra-array/wiki/randomSuffix)
Parameter x
an array
Parameter n
number of values [-1 β any]
Parameter fr
random number generator ([0, 1))
Returns
x[|x|-i..] if n<0; x[|x|-n..] otherwise | i β 0..|x|
function suffixes
suffixes: <T>(x: T[], n?: number) => T[][];
Obtain all possible suffixes. [π](https://github.com/nodef/extra-array/wiki/suffixes)
Parameter x
an array
Parameter n
number of values [-1 β any]
Returns
[x[0..], x[1..], x[2..], ...] if n<0; [x[-n..]] otherwise
function swap
swap: <T>(x: T[], i: number, j: number) => T[];
Exchange two values. [π](https://github.com/nodef/extra-array/wiki/swap)
Parameter x
an array
Parameter i
an index
Parameter j
another index
Returns
x' | x' = x; x'[i] = x[j]; x'[j] = x[i]
function swap$
swap$: <T>(x: T[], i: number, j: number) => T[];
Exchange two values! [π](https://github.com/nodef/extra-array/wiki/swap$)
Parameter x
an array (updated!)
Parameter i
an index
Parameter j
another index
Returns
x | x[i] β x[j]
function swapRanges
swapRanges: <T>(x: T[], i: number, I: number, j: number, J: number) => T[];
Exchange two ranges of values. [π](https://github.com/nodef/extra-array/wiki/swapRanges)
Parameter x
an array
Parameter i
begin index of first range
Parameter I
end index of first range (exclusive)
Parameter j
begin index of second range
Parameter J
end index of second range (exclusive)
Returns
x' | x' = x; x'[i..I] = x[j..J]; x'[j..J] = x[i..I]
function swapRanges$
swapRanges$: <T>(x: T[], i: number, I: number, j: number, J: number) => T[];
Exchange two ranges of values! [π](https://github.com/nodef/extra-array/wiki/swapRanges$)
Parameter x
an array (updated!)
Parameter i
begin index of first range
Parameter I
end index of first range (exclusive)
Parameter j
begin index of second range
Parameter J
end index of second range (exclusive)
Returns
x | x[i..I] β x[j..J]
function symmetricDifference
symmetricDifference: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Obtain values not present in both arrays. [π](https://github.com/nodef/extra-array/wiki/symmetricDifference)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x-y βͺ y-x
function tail
tail: <T>(x: T[]) => T[];
Get values except first. [π](https://github.com/nodef/extra-array/wiki/tail)
Parameter x
an array
Returns
x[1..|x|]
function take
take: <T>(x: T[], n?: number) => T[];
Keep first n values only. [π](https://github.com/nodef/extra-array/wiki/take)
Parameter x
an array
Parameter n
number of values [1]
Returns
x[0..n]
function takeRight
takeRight: <T>(x: T[], n?: number) => T[];
Keep last n values only. [π](https://github.com/nodef/extra-array/wiki/takeRight)
Parameter x
an array
Parameter n
number of values [1]
Returns
x[0..n]
function takeWhile
takeWhile: <T>(x: T[], ft: TestFunction<T>) => T[];
Keep values from left, while a test passes. [π](https://github.com/nodef/extra-array/wiki/takeWhile)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
x[0..T-1] | ft(x[i]) = true β i β [0, T-1] & ft(x[T]) = false
function takeWhileRight
takeWhileRight: <T>(x: T[], ft: TestFunction<T>) => T[];
Keep values from right, while a test passes. [π](https://github.com/nodef/extra-array/wiki/takeWhileRight)
Parameter x
an array
Parameter ft
test function (v, i, x)
Returns
x[T..] | ft(x[i]) = true β i β [T, |x|-1] & ft(x[T-1]) = false
function toReversed
toReversed: <T>(x: T[]) => T[];
Reverse the values. [π](https://github.com/nodef/extra-array/wiki/reverse)
Parameter x
an array
Returns
[x[|x|-1], x[|x|-2], ..., x[1], x[0]]
function toSorted
toSorted: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null, fs?: SwapFunction<T> | null) => T[];
Arrange values in order. [π](https://github.com/nodef/extra-array/wiki/sort)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Parameter fs
swap function (x, i, j)
Returns
x' | x' = x; x'[i] β€ x'[j] β i β€ j
function toSpliced
toSpliced: <T>(x: T[], i: number, n?: number, ...vs: T[]) => T[];
Remove or replace existing values. [π](https://github.com/nodef/extra-array/wiki/splice)
Parameter x
an array
Parameter i
remove Β±index
Parameter n
number of values to remove [rest]
Parameter vs
values to insert
Returns
x[0..i] β§Ί vs β§Ί x[i+n..]
function union
union: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Obtain values present in any array. [π](https://github.com/nodef/extra-array/wiki/union)
Parameter x
an array
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x βͺ y = {v | v β x or v β y}
function union$
union$: <T, U = T>( x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Obtain values present in any array! [π](https://github.com/nodef/extra-array/wiki/union$)
Parameter x
an array (updated!)
Parameter y
another array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
x = x βͺ y = {v | v β x or v β y}
function unique
unique: <T, U = T>( x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null) => T[];
Remove duplicate values. [π](https://github.com/nodef/extra-array/wiki/unique)
Parameter x
an array
Parameter fc
compare function (a, b)
Parameter fm
map function (v, i, x)
Returns
vβ, vβ, ... | vα΅’ β x; vα΅’ β vβ±Ό β i, j
function unshift
unshift: <T>(x: Iterable<T>, ...vs: T[]) => T[];
Add values to the start. [π](https://github.com/nodef/extra-array/wiki/unshift)
Parameter x
an array
Parameter vs
values to add
Returns
vs β§Ί x
function unshift$
unshift$: <T>(x: T[], ...vs: T[]) => T[];
Add values to the start! [π](https://github.com/nodef/extra-array/wiki/unshift$)
Parameter x
an array (updated!)
Parameter vs
values to add
Returns
x = vs β§Ί x
function value
value: <T>(x: T[], fr?: ReadFunction<number> | null) => T;
Pick an arbitrary value. [π](https://github.com/nodef/extra-array/wiki/randomValue)
Parameter x
an array
Parameter fr
random number generator ([0, 1))
Returns
x[i] | i β 0..|x|
function values
values: <T>(x: T[]) => T[];
Get all values. [π](https://github.com/nodef/extra-array/wiki/values)
Parameter x
an array
Returns
[vβ, vβ, ...] | vα΅’ = x[i]
function with
with: <T>(x: T[], i: number, v: T) => T[]
Set value at index. [π](https://github.com/nodef/extra-array/wiki/set)
Parameter x
an array
Parameter i
index
Parameter v
value
Returns
x' | x' = x; x'[i] = v
function zip
zip: <T, U = T[]>( xs: T[][], fm?: MapFunction<T[], T[] | U> | null, fe?: EndFunction, vd?: T) => (T[] | U)[];
Combine values from arrays. [π](https://github.com/nodef/extra-array/wiki/zip)
Parameter xs
arrays
Parameter fm
map function (vs, i)
Parameter fe
end function (dones) [some]
Parameter vd
default value
Returns
[fm([xβ[0], xβ[0], ...]), fm([xβ[1], xβ[1], ...]), ...]
Type Aliases
type CombineFunction
type CombineFunction<T> = (a: T, b: T) => T;
Handle combining of two values. [π](https://github.com/nodef/extra-array/wiki/CombineFunction)
Parameter a
a value
Parameter b
another value
Returns
combined value
type CompareFunction
type CompareFunction<T> = (a: T, b: T) => number;
Handle comparison of two values. [π](https://github.com/nodef/extra-array/wiki/CompareFunction)
Parameter a
a value
Parameter b
another value
Returns
a<b: -ve, a=b: 0, a>b: +ve
type EndFunction
type EndFunction = (dones: boolean[]) => boolean;
Handle ending of a combined array. [π](https://github.com/nodef/extra-array/wiki/EndFunction)
Parameter dones
iα΅Κ° array done?
Returns
combined array done?
type Entries
type Entries<T> = [number, T][];
Entries is an array of index-value pairs, with unique indices. [π](https://github.com/nodef/extra-array/wiki/Entries)
type IEntries
type IEntries<T> = Iterable<[number, T]>;
IEntries is a list of index-value pairs, with unique indices. [π](https://github.com/nodef/extra-array/wiki/IEntries)
type ILists
type ILists<T> = [Iterable<number>, Iterable<T>];
ILists is a pair of index iterable list and value iterable list, with unique indices. [π](https://github.com/nodef/extra-array/wiki/ILists)
type Lists
type Lists<T> = [number[], T[]];
Lists is a pair of index array and value array, with unique indices. [π](https://github.com/nodef/extra-array/wiki/Lists)
type MapFunction
type MapFunction<T, U> = (v: T, i: number, x: T[]) => U;
Handle transformation of a value to another. [π](https://github.com/nodef/extra-array/wiki/MapFunction)
Parameter v
value in array
Parameter i
index of value in array
Parameter x
array containing the value
Returns
transformed value
type ProcessFunction
type ProcessFunction<T> = (v: T, i: number, x: T[]) => void;
Handle processing of values in an array. [π](https://github.com/nodef/extra-array/wiki/ProcessFunction)
Parameter v
value in array
Parameter i
index of value in array
Parameter x
array containing the value
type ReadFunction
type ReadFunction<T> = () => T;
Handle reading of a single value. [π](https://github.com/nodef/extra-array/wiki/ReadFunction)
Returns
value
type ReduceFunction
type ReduceFunction<T, U> = (acc: U, v: T, i: number, x: T[]) => U;
Handle reduction of multiple values into a single value. [π](https://github.com/nodef/extra-array/wiki/ReduceFunction)
Parameter acc
accumulator (temporary result)
Parameter v
value in array
Parameter i
index of value in array
Parameter x
array containing the value
Returns
reduced value
type SwapFunction
type SwapFunction<T> = (x: T[], i: number, j: number) => T[];
Handle swapping of two values in an array. [π](https://github.com/nodef/extra-array/wiki/SwapFunction)
Parameter x
an array (updated!)
Parameter i
an index
Parameter j
another index
Returns
x | x[i] β x[j]
type TestFunction
type TestFunction<T> = (v: T, i: number, x: T[]) => boolean;
Handle selection of values in an array. [π](https://github.com/nodef/extra-array/wiki/TestFunction)
Parameter v
value in array
Parameter i
index of value in array
Parameter x
array containing the value
Returns
selected?
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (10)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/extra-array
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/extra-array)
- HTML<a href="https://www.jsdocs.io/package/extra-array"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 6194 ms. - Missing or incorrect documentation? Open an issue for this package.