Skip to content

Instantly share code, notes, and snippets.

@fasidOnGit
Created April 20, 2019 02:45
Show Gist options
  • Save fasidOnGit/45a8045e65a306ef13f4b22ad2b94649 to your computer and use it in GitHub Desktop.
Save fasidOnGit/45a8045e65a306ef13f4b22ad2b94649 to your computer and use it in GitHub Desktop.
/**
* Flattens any levels of nested arrays into single level
* @author Kader Fasid(fasidmpm@gmail.com)
* @params {Array} - Nested Array to Flatten
* @returns {Array} - Flattened array.
*/
const flatten = (input) => {
var arr = [];
const recursiveArr = (input) => {
if(Array.isArray(input)) {
input.forEach(x => recursiveArr(x));
} else {
arr.push(input);
}
}
recursiveArr(input)
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment