Properties

Properties

static

incl

Alias for iter_utils.includes

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to check

value

T

 

The value to check for

start_index

number

Yes

The index to start checking from

Defaults to 0.

Returns

boolean 

static

includes

Checks if an iterable includes a value. Uses iter_utils.count.

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to check

value

T

 

The value to check for

start_index

number

Yes

The index to start checking from

Defaults to 0.

Returns

boolean 

Methods

static

alleq(iter) → boolean

Checks if all items in an iterable are equal

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to check

Returns

boolean 

static

append(array, ...items) → Array of T

Same as the built in Array.push

Parameters

Name Type Optional Description

array

Array of T

 

The array to append to

items

T

 

The items to append

Value can be repeated.

Returns

Array of T 

The resulting array

static

at(iter, index) → T

Gets the element at index in iter. Indices wrap around using math_utils.wrapindex. If index is a Vec, iter will be treated as a grid, or if index is a list of integers, a list of elements at those indices will be returned.

Parameters

Name Type Optional Description

iter

Iterable containing (T or Iterable containing T)

 

The iterable to get elements from

index

(number, Vec, or Array of number)

 

The index/indicies to get

Returns

T 

static

chunks(iter[, size]) → Array of Array of T

Creates a list of contiguous non-overlapping chunks of iter, each of length size

Examples

[1, 2, 3, 4, 5, 6].chunks() // [[1, 2], [3, 4], [5, 6]]
[1, 2, 3, 4, 5, 6].chunks(3) // [[1, 2, 3], [4, 5, 6]]

Parameters

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to create chunks from

size

number

Yes

The size of each chunk

Defaults to 2.

Returns

Array of Array of T 

static

count(iter, value[, string_like_match]) → number

Counts the number of times value appears in iter. If value is a function, it's will do the same as .filter(f).length, if iter is a string or string_like_match is explicitly set to true, ["a", "b"] will match abcd or ["a", "b", "c", "d"] as well as something like ["arstneio", ["a", "b], 4].

Examples

[4, 2, 3, 1, 2].count(2) // 2
"abababa".count("aba") // 2
[3, 2, 1, 2, 1].count([2, 1]) // 0
[3, 2, 1, 2, 1].count([2, 1], true) // 2

Parameters

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to count values in

value

any

 

The value to count

string_like_match

boolean

Yes

(See description)

Defaults to false.

Returns

number 

static

countol(iter, value[, string_like_match]) → number

Same as iter_utils.count but counts overlapping matches

Examples

"abababa".countol("aba") // 3
[1, 2, 1, 2, 1].countol([1, 2, 1]) // 2

Parameters

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to count values in

value

any

 

The value to count

string_like_match

boolean

Yes

(See description)

Defaults to false.

Returns

number 

static

deltas(iter) → Array of number

Gets the differences between consecutive elements of an iterable

Example

[1, 2, 9, -4].deltas // [1, 7, -13]

Parameter

Name Type Optional Description

iter

Iterable containing number

 

The iterable to get deltas from

Returns

Array of number 

static

dropnth(iter, index) → Array of T

Removes the nth element from an iterable value

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to remove an element from

index

number

 

The index of the element to remove

Returns

Array of T 

The resulting array

static

each(iter, callback) → Iterable containing T

Same as the built in Array.forEach

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to iterate over

callback

function(T, number, Iterable containing T)

 

The callback to call for each element (see the MDN link for more info)

Returns

Iterable containing T 

The original iterable

static

everynth(iter, n[, start]) → Array of T

Return a list with every nth element of iter starting at index start

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to get elements from

n

number

 

The step size

start

number

Yes

The starting index

Defaults to 0.

Returns

Array of T 

static

filterout(array, filter_fn) → Array of T

Same as the built in Array.filter but inverted. For consistency with builtins like Array.filter and Array.map which don't work on any iterable. This must also be called on an array.

Parameters

Name Type Optional Description

array

Array of T

 

The iterable to filter

filter_fn

function(T)

 

The filter function

Returns

Array of T 

static

first(iter) → any

Gets the first element of an iterable value

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to get the first element from

Returns

any 

static

firstn(iter, n) → Array of T

Gets the first n elements of an iterable value and returns them in an array

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to get elements from

n

number

 

The number of elements to get

Returns

Array of T 

static

flat(iter) → Array of T

Deep flattens an iterable

Example

[[1, [2]], [[[[3, [4, 5]]]]], 6].flat // [1, 2, 3, 4, 5, 6]

Parameter

Name Type Optional Description

iter

Iterable containing T

 

The iterable to flatten

Returns

Array of T 

static

for(iter, callback) → Iterable containing T

Same as the built in Array.forEach

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to iterate over

callback

function(T, number, Iterable containing T)

 

The callback to call for each element (see the MDN link for more info)

Returns

Iterable containing T 

The original iterable

static

iwhere(iter, fn) → Array of number

Returns list of indices where the function fn returns true. fn receives the value, index and the iterable as arguments, in that order.

Example

[1, 2, 3, 4, 5].iwhere(x => x % 2 === 0) // [1, 3]

Parameters

Name Type Optional Description

iter

Iterable containing T

 

fn

function(T, number, Iterable containing T)

 

Returns

Array of number 

static

last(iter) → any

Gets the last element of an iterable value

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to get the last element from

Returns

any 

static

lastn(iter, n) → Array of T

Gets the last n elements of an iterable value and returns them in an array

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to get elements from

n

number

 

The number of elements to get

Returns

Array of T 

static

max(iter) → number

Same as the built in Math.max but it takes an iterable as a single argument

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to find the maximum of

Returns

number 

static

min(iter) → number

Same as the built in Math.min but it takes an iterable as a single argument

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to find the minimum of

Returns

number 

static

nflat(iter[, depth]) → Array of T

Flattens an iterable to a certain depth. Alias for the builtin Array.flat.

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to flatten

depth

number

Yes

The depth to flatten to

Defaults to 1.

Returns

Array of T 

static

none(array, fn) → boolean

Checks if there are no elements in array that satisfy fn. fn is passed to the built in Array.some so refer to those docs if needed.

Parameters

Name Type Optional Description

array

Array of T

 

The array to check

fn

function(T, number, Array of T)

 

The function to check

Returns

boolean 

static

nsort(iter) → Array of T

Sorts an iterable (of numbers) in ascending order

Parameter

Name Type Optional Description

iter

Iterable containing T

 

The iterable to sort

Returns

Array of T 

The sorted array

static

perms(iter) → Array of Array of T

Generates all permutations of an iterable

Parameter

Name Type Optional Description

iter

Iterable containing T

 

Returns

Array of Array of T 

static

pieces(iter, n) → Array of Array of T

Splits an iterable into n pieces. Rounds up if the split is uneven.

Examples

[1, 2, 3, 4, 5, 6].pieces(3) // [[1, 2], [3, 4], [5, 6]]
[1, 2, 3].pieces(2) // [[1, 2], [3]]

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to split

n

number

 

The number of pieces to split into

Returns

Array of Array of T 

static

prepend(array, ...items) → Array of T

Same as the built in Array.unshift

Parameters

Name Type Optional Description

array

Array of T

 

The array to prepend to

items

T

 

The items to prepend

Value can be repeated.

Returns

Array of T 

The resulting array

static

prod(iter) → number

Calculates the product of all values in an iterable

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable

Returns

number 

static

rev(iter) → Array of T

Reverses the elements of an iterable (not in place)

Parameter

Name Type Optional Description

iter

Iterable containing T

 

The iterable to reverse

Returns

Array of T 

The reversed array

static

rsort(iter) → Array of T

Sorts an iterable (of numbers) in descending order

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to sort

Returns

Array of T 

The sorted array

static

rsortby(iter, func) → Array of T

Sorts an iterable in descending order by the result of applying a given function to each element

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to sort

func

function(T)

 

The function to apply to each element

Returns

Array of T 

The sorted array

static

seqs(iter) → Array of Array of T

Returns a list of sublists containing consecutive elements of iter

Parameter

Name Type Optional Description

iter

Iterable containing T

 

The iterable to group

Returns

Array of Array of T 

static

sliding(iter, size[, wrap]) → Array of Array of T

Creates a list of sublists of length size each of which is a sliding window looking into iter starting at index 0 moving along by 1 each time. If loop is true, there will be some extra windows at the end which wrap around to the start.

Examples

[1, 2, 3, 4, 5].sliding(3) // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
[1, 2, 3].sliding(2, true) // [[1, 2], [2, 3], [3, 1]]

Parameters

Name Type Optional Description

iter

Iterable containing Array of T

 

The iterable to create sliding windows from

size

number

 

The size of the sliding window

wrap

boolean

Yes

Whether to include windows that wrap around

Defaults to false.

Returns

Array of Array of T 

static

sortby(iter, func) → Array of T

Sorts an iterable in ascending order by the result of applying a given function to each element

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to sort

func

function(T)

 

The function to apply to each element

Returns

Array of T 

The sorted array

static

sorted(iter, compare_fn) → Array of T

Sorts an iterable given a comparison function (same as Array.sort) but not in place

Parameters

Name Type Optional Description

iter

Iterable containing T

 

The iterable to sort

compare_fn

function(T, T)

 

The comparison function

Returns

Array of T 

The sorted array

static

sum(iter) → (number or string)

Sums the elements of an iterable value

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to sum

Returns

(number or string) 

static

swap(array, index_a, index_b) → Array of T

Swaps the elements at indices index_a and index_b in array. Only works on arrays so that it can be done in place.

Parameters

Name Type Optional Description

array

Array of T

 

The array to swap elements in

index_a

number

 

The index of the first element to swap

index_b

number

 

The index of the second element to swap

Returns

Array of T 

The resulting array

static

uniq(iter) → _Set

Creates a new _Set from an iterable. Same as constructors.set.

Parameter

Name Type Optional Description

iter

Iterable containing any type

 

The iterable to create a set from

Returns

_Set 

static

zip(...iters) → Array of Array of T

[Global] Zips multiple iterable into a single array of arrays, each containing a single element from each iterable. The result will only be as long as the shortest input.

Examples

zip([1, 2, 3], [4, 5, 6]) // [[1, 4], [2, 5], [3, 6]]
zip([1, 2]) // [[1], [2]]

Parameter

Name Type Optional Description

iters

Iterable containing Array of T

 

The iterables to zip

Value can be repeated.

Returns

Array of Array of T