Created
April 20, 2019 02:45
-
-
Save fasidOnGit/45a8045e65a306ef13f4b22ad2b94649 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Flattens any levels of nested arrays into single level | |
* @author Kader Fasid([email protected]) | |
* @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