@jswork/next-flatten
v1.0.2
Published
Flattens `array` a single or multiple level deep.
Downloads
159
Readme
next-flatten
Flattens
array
a single or multiple level deep.
installation
npm install -S @jswork/next-flatten
usage
import '@jswork/next-flatten';
const res = nx.flatten([[1, 2, 3], [4, 5]]);
// [1, 2, 3, 4, 5]
other solution
function flattenArrayOfArrays(a, r) {
if (!r) { r = [] }
for (var i = 0; i < a.length; i++) {
if (a[i].constructor == Array) {
r.concat(flattenArrayOfArrays(a[i], r));
} else {
r.push(a[i]);
}
}
return r;
}
license
Code released under the MIT license.