Flattener is a utility to flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
To run the project, just create a folder and put the file flattener.js
, test.js
and package.json
inside.
- NodeJS >
6.0.0
To install
npm install
To run the code, open the node shell in the project folder (node
) and run
const flattener = require("./flattener")
flattener([[1, 2, [3]], 4])
To run test
npm test
The tests cover multiple scenario: empty cases, undefined input, multiple nested structure.
There's a not exported recursive implementation of the flattener inside the package. This version may be more readable and shorter but can go out of memory for deeply nested arrays, so I preferred to submit the iterative version of it.
- Matteo Madeddu - made2591