Last active
June 23, 2017 20:21
-
-
Save Aerex/9f7cea6fcafb13141ca1511a2e1ccca9 to your computer and use it in GitHub Desktop.
Flatten Array
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
| function flattenArr(input, output){ | |
| if(!Array.isArray(input)){ | |
| return input; | |
| } | |
| var a = null; | |
| for(var i = 0; i < input.length; i++){ | |
| a = flattenArr(input[i], output); | |
| if(a){ | |
| output.push(a); | |
| } | |
| } | |
| } | |
| var input = [[1],2,3,[5]]; | |
| var out = []; | |
| flattenArr(input, out); | |
| console.log(JSON.stringify(out)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment