Last active
August 29, 2015 14:21
-
-
Save francoisromain/ac23c5ff9b48ec030a9c to your computer and use it in GitHub Desktop.
flatten.js
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
// flatten an array | |
// input [[[[1], 2, 3], 4, 5, 6, 7], 8, 9, 10, [11, 12, 13]] | |
// output [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
var flatten = function(e){ | |
var flatArray = []; | |
if (!Array.isArray(e)) { | |
flatArray = flatArray.concat(e); | |
} else { | |
for (var i = 0; i < e.length; i++) { | |
flatten(e[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment