MathUtil
Index
Constructors
constructor
Returns default
Methods
staticcompactMatrix
Compacts a 2D matrix testing entries against a testValue with a default value of
1
for inclusion. The resulting compacted array only has object hash entries for rows that contain column entries that pass the test. Each entry has arow
entry as a number corresponding to a row index and acols
entry which is an array of numbers representing all column indexes that pass the test. This works well for large sparse matrices.Parameters
matrix: number[][]
A matrix to compact / compress.
testValue: number = 1
A value to test strict equality to include entry for compaction.
Returns { cols: number[]; row: number }[]
staticcreate2DArray
Creates an 2-dimensional array of the given length.
Parameters
length: number = 0
Array length for x / y dimensions.
value: number = 0
Default value.
Returns number[][]
staticgetMedian
Returns the median / middle value from the given array after sorting numerically. If values length is odd the middle value in the array is returned otherwise if even two middle values are summed then divided by 2.
Parameters
values: number[]
An Array of numerical values.
Returns number
staticgetPercent
Returns the percent of a given value and limit.
Parameters
value: number
A
value
to calculate the percentage against the givenlimit
.limit: number
A base
limit
that constrains thevalue
.
Returns number
statictoFixed
Converts floating point numbers to a fixed decimal length of 3. This saves space and avoids precision issues with serializing / deserializing.
Parameters
val: number
Any value; only floats are processed.
Returns number
statictoFixedTraverse
Performs a naive depth traversal of an object / array. The data structure must not have circular references. The result of the
toFixed
method is invoked for each leaf or array entry modifying any floating point number in place.Parameters
data: any
An object or array.
Returns any
Provides common math utilities.