Skip to content

Instantly share code, notes, and snippets.

@Nate-Wilkins
Last active August 29, 2015 14:05
Show Gist options
  • Save Nate-Wilkins/a119774bd64e98ee62e0 to your computer and use it in GitHub Desktop.
Save Nate-Wilkins/a119774bd64e98ee62e0 to your computer and use it in GitHub Desktop.
fatten
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