MathUtil
Provides common math utilities.
Static Method Summary
Static Public Methods | ||
public static |
compactMatrix(matrix: Array<Array<number>>, testValue: *): Array<{row: number, cols: Array<number>}>{row:> Compacts a 2D matrix testing entries against a testValue with a default value of |
|
public static |
Creates an 2-dimensional array of the given length. |
|
public static |
Returns the median / middle value from the given array after sorting numerically. |
|
public static |
getPercent(value: number, limit: number): number Returns the percent of a given value and limit. |
|
public static |
toFixed(val: *): * Converts floating point numbers to a fixed decimal length of 3. |
|
public static |
toFixedTraverse(data: object): * Performs a naive depth traversal of an object / array. |
Static Public Methods
public static compactMatrix(matrix: Array<Array<number>>, testValue: *): Array<{row: number, cols: Array<number>}>{row:> source
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 a row
entry as a number corresponding to a row index and a cols
entry which is an array of numbers
representing all column indexes that pass the test. This works well for large sparse matrices.
public static create2DArray(length: number, value: number): Array<Array<number>> source
Creates an 2-dimensional array of the given length.
public static getMedian(values: Array<number>): number source
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.
public static getPercent(value: number, limit: number): number source
Returns the percent of a given value and limit.
public static toFixed(val: *): * source
Converts floating point numbers to a fixed decimal length of 3. This saves space and avoids precision issues with serializing / deserializing.
Params:
Name | Type | Attribute | Description |
val | * | Any value; only floats are processed. |
Return:
* |
public static toFixedTraverse(data: object): * source
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.
Params:
Name | Type | Attribute | Description |
data | object | An object or array. |
Return:
* |