Skip to content

Instantly share code, notes, and snippets.

@witalobenicio
Last active October 24, 2019 16:23
Show Gist options
  • Save witalobenicio/6391e55a1dbfc0693486dd80bd0c4fe1 to your computer and use it in GitHub Desktop.
Save witalobenicio/6391e55a1dbfc0693486dd80bd0c4fe1 to your computer and use it in GitHub Desktop.
Deeply Flatt Array
// @flow
const flattenDeep = (arr: Array<number>], flatArr = []) => {
const length = !arr ? 0 : arr.length;
let index = 0;
while(index < length) {
if (Array.isArray(arr[index])) {
flatDeep(arr[index], flatArr);
} else {
flattArr[flattenArr.length] = arr[index];
}
index += 1;
}
return flatArr;
}
const flattenArray = (arr: Array<number>) => {
return flattenDeep(arr);
};
export default flattenArray;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment