Link Search Menu Expand Document

Arrays

arrays.ts#L162

Interface LinkedListItem

Property .next

Property .val : T

arrays.ts#L122

chunk (array: Array<T>, n: number): Array<Array<T>>

Breaks an array into chunks of size at most n.

Name Type Default Description
array Array<T>    
n number    
arrays.ts#L115

cumulative (array: Array<number>): Array<number>

Creates a cumulative array by adding its elements.

Name Type Default Description
array Array<number>    
arrays.ts#L149

difference (a1: Array<T>, a2: Array<T>): Array<T>

Returns all elements that are only in one of a1 and a2.

Name Type Default Description
a1 Array<T>    
a2 Array<T>    
arrays.ts#L108

flatten (array: Array<any>): Array<T>

Flattens a nested array into a single list.

Name Type Default Description
array Array<any>    
arrays.ts#L143

intersect (a1: Array<any>, a2: Array<any>): Array<any>

Returns all elements that are in both a1 and a2.

Name Type Default Description
a1 Array<any>    
a2 Array<any>    
arrays.ts#L157

join (arrays: Array<Array<any>>): Array<any>

Join multiple Arrays

Name Type Default Description
arrays Array<Array<any>>    
arrays.ts#L70

last (array: Array<T>, i: number): T

Returns the last item in an array, or the ith item from the end.

Name Type Default Description
array Array<T>    
i number 0  
arrays.ts#L52

list (a: number, b: number, step: number): Array<number>

Creates an array of numbers from 0 to a, or from a to b.

Name Type Default Description
a number    
b number    
step number 1  
arrays.ts#L95

loop (array: Array<T>): (): T

Returns a function that can be called repeatedly, and returns items of the array, continuously looping

Name Type Default Description
array Array<T>    
arrays.ts#L8

repeat (value: T, n: number): Array<T>

Creates an array of size n, containing value at every entry.

Name Type Default Description
value T    
n number    
arrays.ts#L14

repeat2D (value: T, x: number, y: number): Array<Array<T>>

Creates a matrix of size x by y, containing value at every entry.

Name Type Default Description
value T    
x number    
y number    
arrays.ts#L132

rotate (array: Array<T>, offset: number): Array<T>

Rotates the elements of an array by offset.

Name Type Default Description
array Array<T>    
offset number 1  
arrays.ts#L82

sortBy (array: Array<T>, fn: (x: T): any, reverse: boolean): Array<T>

Sorts an array by the return value when evaluating a given function.

Name Type Default Description
array Array<T>    
fn (x: T): any    
reverse boolean false  
arrays.ts#L24

tabulate (fn: (i: number): T, n: number): Array<T>

Creates an array of size n, with the result of fn(i) at position i.

Name Type Default Description
fn (i: number): T    
n number    
arrays.ts#L37

tabulate2D (fn: (i: number, j: number): T, x: number, y: number): Array<Array<T>>

Creates a matrix of size x by y, with the result of fn(i, j) at position (i, j.

Name Type Default Description
fn (i: number, j: number): T    
x number    
y number    
arrays.ts#L168

toLinkedList (array: Array<T>): Array<LinkedListItem<T>>

Converts an array to a linked list data structure.

Name Type Default Description
array Array<T>    
arrays.ts#L76

total (array: Array<number>): number

Finds the sum of all elements in an numeric array.

Name Type Default Description
array Array<number>    
arrays.ts#L102

unique (array: Array<T>): Array<T>

Filters all duplicate elements from an array.

Name Type Default Description
array Array<T>    

Copyright © 2021 Mathigon.org