Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 1.29 KB

Readme.md

File metadata and controls

43 lines (28 loc) · 1.29 KB

flat-map

Build status Git tag NPM version Code style

Map over a (possibly nested) list, executing a function on each scalar item, and returning the result as a flat list

Installation

$ npm install @f/flat-map

Usage

var flatMap = require('@f/flat-map')

flatMap(n => n + 1, [[2, 3], [4, 5]]) // -> [3, 4, 5, 6]

API

flatMap(fn, arr)

  • fn - Function to map the elements of arr and its sublists over
  • arr - Possibly nested array to be mapped over fn

Returns: Returns a flat list, with each scalar element in arr (no matter how deeply nested) replaced with the result of fn(value).

License

MIT