A one-liner function that flattens arrays.
npm install @lamansky/flattenA one-liner function that flattens arrays.
Requires Node.js 6.0.0 or above.
``bash`
npm i @lamansky/flatten
The module exports a single function.
1. Bindable: arr (Array): The array to be flatteneddepth
2. Object argument:
* Optional: (integer): Defaults to Infinity. If 0, the original arr is returned.
The flattened Array
`javascript
const flatten = require('@lamansky/flatten')
const arr = [[[1], 2], [3]]
flatten(arr) // [1, 2, 3]
flatten(arr, {depth: 1}) // [[1], 2, 3]
flatten(arr, {depth: 0}) // [[[1], 2], [3]]
// Supports the bind operator
arr::flatten() // [1, 2, 3]
arr::flatten({depth: 1}) // [[1], 2, 3]
``