require.mx('mxjs/base/xutilities.js');
This utilities lib contains utilites for: dates, maths, arrays, asserts, conversions and misc.
These functions, where possible, should be used to avoid common coding errors.
AVALIABLE UTILITIES:
const array_uti = utilities.xarray;
const assert_uti = utilities.xassert;
const conv_uti = utilities.xconvert;
const math_uti = utilities.xmath;
const group_uti = utilities.xgroup;
const misc_uti = utilities.xmisc;
EXAMPLE IMPLEMENTATION:
const utilities = require.mx('mxjs/base/xutilities.js')
//load utility lib
const assert_uti = utilities.xassert;
//Optional parse of the individual utility libraries
utilities are accessed as (if not parsed):
utilities.xassert.isnum(1);
returns true;
OR (if parsed)
date_uti.isnum('hello_world');
returns false;
Status | Name |
---|---|
Array xarray.argsort
(
Array ↓array,
Function ↓comparefn
)
Returns an array containing the indices of the input array, sorted by the values stored at those indices (using the given comparison function) . c.f. numpy's argsort https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.argsort.html |
|
Number xarray.clone_obj
(
Number Placeholder
)
|
|
Number xarray.copy
(
Number Placeholder
)
|
|
Number xarray.equal_range
(
Number Placeholder
)
|
|
Number xarray.find_first_not_equal
(
Number Placeholder
)
|
|
Array xarray.get_unique_elements
(
Array ↓array,
Function equalfn,
Function comparefn
)
Returns an array containing the unique elements from the given input array. Uniqueness is tested using the !== operator by default. |
|
xarray.insertElement
(
Array array,
Object itemToInsert,
Number index,
Number arraySize
)
Inserts an element into an array at specified location |
|
Number xarray.lower_bound
(
Number Placeholder
)
|
|
T xarray.maxElement
(
Array ↓array
)
Returns the value of the element in the array (if the array has at least one element) that has the maximum value (using the > operator). |
|
Int32 xarray.maxElementIndex
(
Array ↓array
)
Returns the index of the element in the array (if the array has at least one element) that has the maximum value (using the > operator). |
|
xarray.moveElement
(
Array array,
Number fromIndex,
Number toIndex
)
moves an element within an array |
|
Number xarray.print_obj
(
Number Placeholder
)
|
|
Array xarray.sort_array
(
Array ⇅array
)
Sorts an array based on the contained values OR strings
|
|
Array xarray.sort_nested_array
(
Array ⇅array,
Number ↓index
)
Sorts a nested array based on an array index
|
|
Number xarray.sort_three_numbered_array
(
Number Placeholder
)
|
|
Number xarray.starts_with
(
Number Placeholder
)
|
|
Number xarray.starts_with_N
(
Number Placeholder
)
|
|
Array xarray.transform_array
(
Array ⇅array,
Number ↓arraySize,
Function ↓Function
)
Executes the provided function over each element of the provided array and replaces the element with the result of the function execution. |
|
Array xarray.transform_nested_array
(
Array ⇅array,
Number ↓nestedIndex,
Number ↓arraySize,
Function ↓Function
)
Executes the provided function over each element, at the specified index, of the provided nested array and replaces the element with the result of the function execution. |
|
Number xarray.update
(
Number Placeholder
)
|
|
Number xarray.upper_bound
(
Number Placeholder
)
|
|
Number xassert.assert
(
Number Placeholder
)
|
|
Number xassert.assert_arguments_valid_num
(
Number Placeholder
)
|
|
Number xassert.assert_valid_num
(
Number Placeholder
)
|
|
Number xassert.invalid_to_null
(
Number Placeholder
)
|
|
Number xassert.isnum
(
Number Placeholder
)
|
|
Number xdate.calc_iso_week
(
Number Placeholder
)
|
|
Number xdate.calc_iso_week_ymd
(
Number Placeholder
)
|
|
Number xdate.calc_time_period_ms
(
Number Placeholder
)
|
|
Number xdate.calc_week_startdate_ms
(
Number Placeholder
)
|
|
Number xdate.get_hours
(
Number Placeholder
)
|
|
Number xdate.get_minutes
(
Number Placeholder
)
|
|
xdate.pad_2
(
Point {Number}
)
txt |
|
Number xdate.pad_3
(
Number Placeholder
)
|
|
Number xdate.remove_time
(
Number Placeholder
)
|
|
Number xdate.str_utc
(
Number Placeholder
)
|
|
Number xdate.str_utc_ms
(
Number Placeholder
)
|
|
Number xgroup. extract_groups
(
Number Placeholder
)
|
|
Number xgroup.discover_no_overlap
(
Number Placeholder
)
|
|
Number xgroup.no_overlap
(
Number Placeholder
)
|
|
Number xgroup.print_group_info
(
Number Placeholder
)
|
|
xmath.cbrt
(
Number ↓x
)
= 3√x |
|
Number xmath.clamp
(
Number Placeholder
)
|
|
xmath.cube(x)
(
Number ↓x
)
= x 3 |
|
xmath.dist
(
[x1,y1,z1],[x2,y2,z2] ↓x
)
= distance between point a and b |
|
xmath.exp
(
Number ↓x
)
= e x where e is the "Euler number", 2.71828... |
|
xmath.exp10
(
Number ↓x
)
= 10 x |
|
xmath.ln
(
Number ↓x
)
= ln(x) |
|
xmath.log10
(
Number ↓x
)
= log 10 |
|
Number xmath.log2
(
Number ↓x
)
`log_2` |
|
Number xmath.numdigit
(
Number ↓x,
Number ↓numdigit
)
rounds a number 'x' to number of digits. e.g. rounding 123456 to 4 digits will return 123500. |
|
xmath.pow10
(
Number ↓x
)
= exp10(x) = 10 x |
|
Number xmath.rd
(
Number ↓x,
Number ↓dp
)
rounds a number 'x' to 'dp' number of places |
|
xmath.sqr
(
Number ↓x
)
= x 2 |
|
xmath.sqr_dist
(
↓{[x1,y1,z1],[x2,y2,z2]}
)
= squared distance between point a and b |
|
xmath.sqrt
(
Number ↓x
)
= √x |
|
Number xmisc.compare
(
Number Placeholder
)
|
|
Number xmisc.pointstats
(
Number Placeholder
)
|
Returns an array containing the indices of the input array, sorted by the values stored at those indices (using the given comparison function) . c.f. numpy's argsort https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.argsort.html
Parameters: Returns:Array
indices - the indices of the sorted arrayReturns an array containing the unique elements from the given input array. Uniqueness is tested using the !== operator by default.
Parameters:Array
↓array - the input arrayFunction
equalfn - function (a, b) -> bool (true if a and b are the same)Function
comparefn - comparison function to use with Array.sort (internally used to simplify the uniqueness checking: non-unique items should be next to each other in sorted order)Array
uniques - array containing the unique elementsReturns the value of the element in the array (if the array has at least one element) that has the maximum value (using the > operator).
Parameters:Array
↓array - the input arrayT
value - the maximum value of all elements in the arrayReturns the index of the element in the array (if the array has at least one element) that has the maximum value (using the > operator).
Parameters:Array
↓array - the input arrayInt32
index - the index of the maximum value of all elements in the arraySorts an array based on the contained values OR strings
WARNING: Inherents some limitations of the .sort() array method
e.g. A = [99,-99,0];
A.sort(sort_array);
A = [-99,0,99];
OR
A = ['z','a','Z', 'A'];
A.sort(sort_array);
A = [A,Z,a,z];
Note: Do not pass in arrays of mixed values and strings for sorting using this method.
Array
⇅array - An array for sortingArray
⇅array - the array that was passed in for sorting.Sorts a nested array based on an array index
WARNING: Inherents some limitations of the .sort() array method
const sorting_function = sort_nested_array(1);
e.g. A = [[-1,9,X],[1,1,z],[0,4,q]];
B = sort_nested_array(A,1);
A = [[1,1,z],[0,4,q],[-1,9,X]];
Note: Do not pass in arrays of mixed values and strings for the same index for sorting using this method.
Array
⇅array - the array that was passed in for sorting.Executes the provided function over each element of the provided array and replaces the element with the result of the function execution.
Parameters:Array
⇅array - array to be transformedNumber
↓arraySize - optional - size of array (if reusing array). If not specified, array.length will be used.Function
↓Function - A function that takes a single parameter (each element of the array) and returns a value.Array
⇅array - array that was passed in to be transformedExecutes the provided function over each element, at the specified index, of the provided nested array and replaces the element with the result of the function execution.
Parameters:Array
⇅array - array of arrays to be transformedNumber
↓nestedIndex - the index of the element within each nested array to be transformedNumber
↓arraySize - optional - size of array of arrays. If not specified, array.length will be used.Function
↓Function - A function that takes a single parameter (each element) and returns a value.Array
⇅array - array that was passed in to be transformed
This library provides some groupby functions
QUICK START:
//note: This assumes you have grouped by the group in the table calc input.
//Load script and find groups
const xgroup_utility = require.mx('mxjs/base/utilities/group.js');
const group_object = {};
xgroup_utility.extract_groups(table_name, 'group_read_function', group_object)
xgroup_utility.print_group_info(group_object);
//this logs all group results
//common group usage
for (let group in group_object) {
//For all group results groups in group_object
const start_i = group_object[group].StartIDX;
const end_i = group_object[group].EndIDX;
const n = group_object[group].n;
const name = group_object[group].name;
for(let i = start_i; i <= end_i; ++i){ //do some stuff for the indices
//add function in here!
}
}
= 3√x
Parameters:Number
↓x = x 3
Parameters:Number
↓x = distance between point a and b
Parameters:[x1,y1,z1],[x2,y2,z2]
↓x = e x where e is the "Euler number", 2.71828...
Parameters:Number
↓x = 10 x
Parameters:Number
↓x = ln(x)
Parameters:Number
↓x = log 10
Parameters:Number
↓x = exp10(x) = 10 x
Parameters:Number
↓x = x 2
Parameters:Number
↓x = squared distance between point a and b
Parameters:= √x
Parameters:Number
↓x