Last active
July 17, 2017 23:43
-
-
Save vacas/eb42169c2241ca515ea61e1e91178637 to your computer and use it in GitHub Desktop.
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
// After reviewing the exercise again, I thought this revision is much cleaner and wanted to take out the extra function to not overcomplicate it | |
function flatten_array(input){ | |
var result = []; | |
for (var i = 0; i < input.length; i++){ | |
var flattened = input[i]; | |
result = result.concat(Array.isArray(flattened) ? flatten_array(flattened) : flattened); | |
} | |
return result; | |
} | |
console.log(flatten_array([[1,2,[3]],4])); | |
console.log(flatten_array([[1,2,[3]],4, [5, 6, 8, [9, 10, [11, [12, [13, [14, 15, [16, 105, [109302940, 31409024, [9594590850]]]]]]]]]])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment