Skip to content

Instantly share code, notes, and snippets.

@shawndumas
Created November 30, 2014 02:46
Show Gist options
  • Save shawndumas/c4f8ef33210714368fb6 to your computer and use it in GitHub Desktop.
Save shawndumas/c4f8ef33210714368fb6 to your computer and use it in GitHub Desktop.
[0, ['a', 'b', 'c'], 2, 'd', 4, 5, 'f', 7, ['g', 'h'], 9].reduce(function rec (prev, curr) {
if (/array/i.test(curr.constructor)) {
return curr.reduce(rec, prev);
} else if (/string/i.test(curr.constructor)) {
prev.push(curr);
}
return prev;
}, []);
//["a", "b", "c", "d", "f", "g", "h"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment