datapipe-js/array
datapipe-js/array contains a set of functions to transform, aggregate and join JavaScript arrays.
#
Data Transformation functions#
groupByGroups array items based on elementSelector function
#
pivotReturns 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
#
transposeReturns a transposed array, where rows become columns
#
selectCreates new array based on selector.
- array The array to process.
- elementSelector A Selector function that is invoked per iteration.
#
mapAlias for select and has same usage
#
whereFilters array based on predicate function.
- array The array to process.
- predicate A predicate function to filter items.
#
filterAlias for where and has same usage
#
flatternReturns a flatern array.
- array The array to flatten recursively.
Example
#
sortA simple sort array function with a convenient interface
- array The array to process.
- fields field names with a sort order.
example
#
Joining JavaScript arrays#
leftJoinReturns 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 */
#
innerJoinJoins 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 */
#
fullJoinReturns 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 */
#
mergeMerges 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#
sumSum of items in array.
- array The array to process.
- elementSelector Function invoked per iteration.
example
#
avgAverage of array items.
- array The array to process.
- elementSelector Function invoked per iteration.
#
averageAlias for average and has same usage
#
minComputes the minimum value of array.
- array The array to process.
- elementSelector Function invoked per iteration.
#
maxComputes the maximum value of array.
- array The array to process.
- elementSelector Function invoked per iteration.
#
countCount of elements in array with optional predicate.
- array The array to process.
- predicate Predicate function invoked per iteration.
#
firstGets first item in array that satisfies optional predicate.
- array The array to process.
- predicate Predicate function invoked per iteration.
#
lastGets last item in array that satisfies optional predicate.
- array The array to process.
- predicate Predicate function invoked per iteration.
#
countByGets counts map of values returned by elementSelector
.
- array The array to process.
- elementSelector Function invoked per iteration.
#
meanGet mean of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
#
quantileGet quantile of a sorted array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
- p quantile.
#
varianceGet sample variance of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
#
stdevGet the sample standard deviation of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.
#
medianGet median of an array.
- array The array to process.
- field Property name or Selector function invoked per iteration.