Map over a (possibly nested) list, executing a function on each scalar item, and returning the result as a flat list
$ npm install @f/flat-map
var flatMap = require('@f/flat-map')
flatMap(n => n + 1, [[2, 3], [4, 5]]) // -> [3, 4, 5, 6]
fn
- Function to map the elements ofarr
and its sublists overarr
- Possibly nested array to be mapped overfn
Returns: Returns a flat list, with each scalar element in arr
(no matter how deeply nested) replaced with the result of fn(value)
.
MIT