-
Notifications
You must be signed in to change notification settings - Fork 5
flat
Subhajit Sahu edited this page May 3, 2023
·
20 revisions
Flatten nested array to given depth.
function flat(x, n, fm, ft)
// x: a nested array
// n: maximum depth [-1 ⇒ all]
// 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.flat(x);
// → [ 1, 2, 3, 4, 5 ]
xarray.flat(x, 1);
// → [ 1, 2, 3, [ 4, [ 5 ] ] ]
xarray.flat(x, 2);
// → [ 1, 2, 3, 4, [ 5 ] ]