datapipe-js/array
datapipe-js/array contains a set of functions to transform, aggregate and join JavaScript arrays.
Data Transformation functions#
groupBy#
Groups array items based on elementSelector function
pivot#
Returns a reshaped array based on unique column values.
- array array to pivot
- rowFields row fields (or index fields). It can be one or more field names
- columnField a field which values will be used to create columns
- dataField a dataField which will be aggrated with aggregate function and groupped by rows and columns
- aggFunction an aggregation function. Default value is sum. data field will be aggregated by this function
- columnValues an optional initial column values. Use it to define a set of columns/values you would expect
transpose#
Returns a transposed array, where rows become columns
select#
Creates new array based on selector.
- array The array to process.
- elementSelector A Selector function that is invoked per iteration.
map#
Alias for select and has same usage
where#
Filters array based on predicate function.
- array The array to process.
- predicate A predicate function to filter items.
filter#
Alias for where and has same usage
flattern#
Returns a flatern array.
- array The array to flatten recursively.
Example
sort#
A simple sort array function with a convenient interface
- array The array to process.
- fields field names with a sort order.
example
Joining JavaScript arrays#
leftJoin#
Returns a joined array with all elements from the left array (leftArray), and the matched elements from the right array (rightArray). The result is NULL from the right side, if there is no match.
- leftArray array for left side in a join
- rightArray array for right side in a join
- leftKey A key from left side array. What can be as a fieldName, multiple fields or key Selector
- rightKey A key from right side array. what can be as a fieldName, multiple fields or key Selector
- resultSelector A callback function that returns result value */
innerJoin#
Joins two arrays together by selecting elements that have matching values in both arrays. If there are elements in any array that do not have matches in other array, these elements will not be shown!
- leftArray array for left side in a join
- rightArray array for right side in a join
- leftKey A key from left side array. What can be as a fieldName, multiple fields or key Selector
- rightKey A key from right side array. what can be as a fieldName, multiple fields or key Selector
- _resultSelecto_r A callback function that returns result value */
fullJoin#
Returns all elements from the left array (leftArray), and all elements from the right array (rightArray). The result is NULL from the right/left side, if there is no match.
- leftArray array for left side in a join
- rightArray array for right side in a join
- leftKey A key from left side array. What can be as a fieldName, multiple fields or key Selector
- rightKey A key from right side array. what can be as a fieldName, multiple fields or key Selector
- resultSelector A callback function that returns result value */
merge#
Merges elements from two arrays. It appends source element or overrides to target array based on matching keys provided
- targetArray target array
- sourceArray source array
- targetKey tartget key field, arry of fields or field serlector
- sourceKey source key field, arry of fields or field serlector
Aggregation and stats functions#
sum#
Sum of items in array.
- array The array to process.
- elementSelector Function invoked per iteration.
example
avg#
Average of array items.
- array The array to process.
- elementSelector Function invoked per iteration.
average#
Alias for average and has same usage
min#
Computes the minimum value of array.
- array The array to process.
- elementSelector Function invoked per iteration.
max#
Computes the maximum value of array.
- array The array to process.
- elementSelector Function invoked per iteration.
count#
Count of elements in array with optional predicate.
- array The array to process.
- predicate Predicate function invoked per iteration.
first#
Gets first item in array that satisfies optional predicate.
- array The array to process.
- predicate Predicate function invoked per iteration.
last#
Gets last item in array that satisfies optional predicate.
- array The array to process.
- predicate Predicate function invoked per iteration.
countBy#
Gets counts map of values returned by elementSelector.
- array The array to process.
- elementSelector Function invoked per iteration.
mean#
Get mean of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
quantile#
Get quantile of a sorted array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
- p quantile.
variance#
Get sample variance of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
stdev#
Get the sample standard deviation of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
median#
Get median of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.