Last active
August 29, 2015 14:05
-
-
Save Nate-Wilkins/a119774bd64e98ee62e0 to your computer and use it in GitHub Desktop.
fatten
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
var flatten = function (v, cb, result) { | |
result = result || []; | |
if (v instanceof Array) { | |
v.forEach(function (v) { flatten(v, cb, result); }); | |
return result | |
} | |
result.push(cb ? cb(v) : v); | |
return result; | |
}; | |
console.log(flatten([ | |
"a", | |
[ | |
"b", | |
"c", [ | |
"d" | |
] | |
] | |
])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment