Functional transformers for object collections using ES6 features (e.g. computed property names)
- Source
See Also
Methods
(inner) sortBy(list, key, descopt) → {Array.<object>}
Sorts the given list
of objects according to the given key
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
list |
Array. |
An object collection |
||
key |
string | The property to sort by |
||
desc |
boolean | <optional> |
false
|
Option to sort in reverse order |
- Source
A sorted copy of list
- Type:
-
Array.
<object>
(inner) frequencyOf(list, group, key, xformopt) → {Array.<{string: number}>}
Collects all the values at the given key
and totals them by applying the
given aggregate function (xform
); returns an ordered summary of totals
for each group
Name | Type | Attributes | Description |
---|---|---|---|
list |
Array. |
An object collection |
|
group |
string | A common property to group the results under |
|
key |
string | A common property whose (numeric) value will be totalled |
|
xform |
Aggregate | <optional> | An aggregating function |
- Source
A mapping of each item in list
to its respective frequency
- Type:
-
Array.
<{string: number}>
Type Definitions
Aggregate(obj1, obj2, prop) → {number}
Takes two objects and the name of a common property, returning the sum of their respective values
Name | Type | Description |
---|---|---|
obj1 |
Object | The first object |
obj2 |
Object | The second object |
prop |
string | The name of a property common to both |
- Source
The sum of the values of each object's common property
- Type:
- number
const fn = (x, y, k) => x[`${k}`] + y[`${k}`]
const h1 = {'height': 7}
const h2 = {'height': 3}
const totalHeight = fn(h1, h2, 'height')
// returns 10