Skip to content

Instantly share code, notes, and snippets.


Zaza ForkInSpace

View GitHub Profile
ForkInSpace / arrayFlatten
Created Nov 17, 2018
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
View arrayFlatten
flatten = (array, result) => {
if(array.length === 0) return result;
let head = array[0];
let rest = array.slice(1);
if (Array.isArray(head)) {
return flatten(head.concat(rest), result);
return flatten(rest, result);
You can’t perform that action at this time.