itertools

Functional transformers for object collections using ES6 features (e.g. computed property names)

See Also

Methods

# (inner) sortBy(list, key, descopt) → {Array.<object>}

Sorts the given list of objects according to the given key

Parameters
Name Type Attributes Default Description
list Array.<object>

An object collection

key string

The property to sort by

desc boolean <optional>
false

Option to sort in reverse order

Returns

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

Parameters
Name Type Attributes Description
list Array.<{string: number}>

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

Returns

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

Parameters
Name Type Description
obj1 Object

The first object

obj2 Object

The second object

prop string

The name of a property common to both

Returns

The sum of the values of each object's common property

Type
  • number
Example

Using an aggregating function

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