Collect the items of the iterator into a map of arrays keyed by the return value of your key generator function.
import { pipe } from "yta";import { groupBy, of } from "yta/async";await pipe( of(5, 42, 101, 13, 2) groupBy((n) => (n % 2 === 0 ? "even" : "odd")), async (entries) => Object.fromEntries(await entries),);// => { "odd": [5, 101, 13], "even": [42, 2] } Copy
import { pipe } from "yta";import { groupBy, of } from "yta/async";await pipe( of(5, 42, 101, 13, 2) groupBy((n) => (n % 2 === 0 ? "even" : "odd")), async (entries) => Object.fromEntries(await entries),);// => { "odd": [5, 101, 13], "even": [42, 2] }
See also:
The native Map object
Map
Optional
Collect the items of the iterator into a map of arrays keyed by the return value of your key generator function.
See also:
The native
Mapobject