-
Notifications
You must be signed in to change notification settings - Fork 5
flatMap
Subhajit Sahu edited this page May 3, 2023
·
15 revisions
Flatten nested array, based on map function.
function flatMap(x, fm, ft)
// x: an array
// fm: map function (v, i, x)
// ft: flatten test function (v, i, x) [is]
const xarray = require('extra-array');
var x = [[1, 2], [3, [4, [5]]]];
xarray.flatMap(x);
// → [ 1, 2, 3, [ 4, [ 5 ] ] ]
xarray.flatMap(x, v => xarray.flat(v, 1));
// → [ 1, 2, 3, 4, [ 5 ] ]
xarray.flatMap(x, v => xarray.flat(v));
// → [ 1, 2, 3, 4, 5 ]