Map
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';
const data = [
{ age: 39, city: `London` },
{ age: 14, city: `Copenhagen` },
{ age: 23, city: `Stockholm` },
{ age: 56, city: `London` }
];
// Whatever the function returns will be the designated group
// for an item
const map = Arrays.groupBy(data, item => item.city);
This yields a Map with keys London, Stockholm and Copenhagen, and the corresponding values.
London: [{ age: 39, city: `London` }, { age: 56, city: `London` }]
Stockhom: [{ age: 23, city: `Stockholm` }]
Copenhagen: [{ age: 14, city: `Copenhagen` }]
Groups data by a function
grouper
, returning data as a map with string keys and array values. Multiple values can be assigned to the same group.grouper
must yield a string designated group for a given item.