Created
February 25, 2019 22:45
-
-
Save arun057/dc086bc4a5b237f8cdd2172789a601fc to your computer and use it in GitHub Desktop.
Flatten Array
This file contains 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
function flattenArray(inputArray) { | |
var resultArray = []; | |
for (var i = 0; i < inputArray.length; i++) { | |
if (typeof(inputArray[i]) == 'number') { | |
resultArray.push(inputArray[i]); | |
} else if (Array.isArray(inputArray[i])) { | |
resultArray = resultArray.concat(flattenArray(inputArray[i])) | |
} | |
} | |
return resultArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment