non-recursive method of flattening an array or arrays and unflattening the result
Install with npm:
$ npm install --save arr-flatten-unflatten
Install with yarn:
$ yarn add arr-flatten-unflatten
const { flatten, unflatten } = require("arr-flatten-unflatten");
let flat = flatten([2, 4, [8, [2, [32, 64]], 7], 5]);
/**
* => {
* "[0]": 2,
* "[1]": 4,
* "[2][0]": 8,
* "[2][1][0]": 2,
* "[2][1][1][0]": 32,
* "[2][1][1][1]": 64,
* "[2][2]": 7,
* "[3]": 5
* }
* */
unflatten(flat);
// => [2, 4, [8, [2, [32, 64]], 7], 5]
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Copyright © 2019, Quernest. Released under the MIT License.