JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q77222F
  • License MIT

Flattens nested array, based on map function.

Package Exports

  • @extra-array/flat-map

Readme

Flattens nested array, based on map function. 🏃 📼 📦 🌔 📒

Alternatives: flat, flatMap.
This is part of package extra-array.

array.flatMap(x, [fn], [ths]);
// x:   an array
// fn:  map function (v, i, x)
// ths: this argument
const array = require('extra-array');

var x = [[1, 2], [3, [4, [5]]]];
array.flatMap(x);
// [ 1, 2, 3, [ 4, [ 5 ] ] ]

array.flatMap(x, v => array.flat(v, 1));
// [ 1, 2, 3, 4, [ 5 ] ]

array.flatMap(x, v => array.flat(v));
// [ 1, 2, 3, 4, 5 ]

references