flatten
A one-liner function that flattens arrays.
Installation
Requires Node.js 6.0.0 or above.
npm i @lamansky/flatten
API
The module exports a single function.
Parameters
- Bindable:
arr
(Array): The array to be flattened - Object argument:
- Optional:
depth
(integer): Defaults to Infinity
. If 0
, the original arr
is returned.
Return Value
The flattened Array
Example
const flatten = require('@lamansky/flatten')
const arr = [[[1], 2], [3]]
flatten(arr)
flatten(arr, {depth: 1})
flatten(arr, {depth: 0})
arr::flatten()
arr::flatten({depth: 1})