Created
October 2, 2018 14:40
-
-
Save kurai021/df844644efbfdae76514a062808a978b to your computer and use it in GitHub Desktop.
Flat a nested 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 flatten(array) { | |
var flat_array = []; | |
array.forEach(function(e){ | |
flat_array = flat_array.concat(e) | |
}) | |
console.log("Flat array: " + flat_array) | |
} | |
flatten([2,4,9,[5,6,[8,10],4],7]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment