Module: utils

utils

Methods

<static> array1d(m, fn) → {Array}

Returns a 1d js array by given dimension and generating function.
Parameters:
Name Type Description
m Number length.
fn module:utils.array1dGenerator | Any Generation function or constant value.
Source:
Returns:
Type
Array

<static> array2d(m, n, fn) → {Array}

Returns a 2d js array by given dimension and generating function.
Parameters:
Name Type Description
m Number number of rows.
n Number number of columns.
fn module:utils.array2dGenerator | Any Generation function or constant value.
Source:
Returns:
Type
Array

<static> byLexical(a, b) → {Number}

Compare two array lexically.
Parameters:
Name Type Description
a Array first array.
b Array second array.
Source:
Returns:
Type
Number

<static> embed(vec, dim) → {Array}

Return a new vector that embeded in new dimension.
Parameters:
Name Type Description
vec Array
dim Number
Source:
Returns:
Type
Array
Examples
[1,2], 3 -> [1,2,0]
[0], 3 -> [0,0,0]

<static> ensureMatrixOfDimension(m, n, msg) → {Contract}

Returns a contract of m by n matrix.
Parameters:
Name Type Description
m Number
n Number
msg String
Source:
Returns:
Type
Contract

<static> ensureVectorOfDimension(m, msg) → {Contract}

Returns a contract of m-D vector
Parameters:
Name Type Description
m Number
msg String
Source:
Returns:
Type
Contract

<static> isIterator(obj) → {Boolean}

Check whether an object is an iterator. An iterator must implement both hasNext() and next() method.
Parameters:
Name Type Description
obj Any
Source:
Returns:
Type
Boolean

<static> isMatrixOfDimension(mat, m, n) → {Boolean}

Check whether an object is a matrix of m by n.
Parameters:
Name Type Description
mat Any
m Number
n Number
Source:
Returns:
Type
Boolean

<static> isVectorOfDimension(vec, m) → {Boolean}

Check whether an object is a vector of length m.
Parameters:
Name Type Description
vec Any
m Number
Source:
Returns:
Type
Boolean

<static> iteratorFromList(lst) → {Iterator}

Return a iterator of the list.
Parameters:
Name Type Description
lst Array
Source:
Returns:
Type
Iterator

<static> listFromIterator(iter) → {Array}

Construct an js array from iterator.
Parameters:
Name Type Description
iter Iterator
Source:
Returns:
Type
Array

<static> minIndex(vec, cmp) → {Index}

Returns the index of the smallest value.
Parameters:
Name Type Description
vec Array
cmp CompareFn | undefined
Source:
Returns:
Type
Index

<static> rotateLeft(arr, offset) → {Array}

Returns a new array that roated by towards left by given offset.
Parameters:
Name Type Description
arr Array
offset Integer
Source:
Returns:
- new rotated array.
Type
Array

<static> rotateRight(arr, offset) → {Array}

Returns a new array that roated by towards right by given offset.
Parameters:
Name Type Description
arr Array
offset Integer
Source:
Returns:
- new rotated array.
Type
Array

<static> uuid() → {String}

Returns a unique identifier.
Source:
Returns:
Type
String

Type Definitions

array1dGenerator(i) → {Any}

Parameters:
Name Type Description
i Number index, starts from 0.
Source:
Returns:
Type
Any

array2dGenerator(i, j) → {Any}

Parameters:
Name Type Description
i Number row index, starts from 0.
j Number column index, starts from 1.
Source:
Returns:
Type
Any