Skip to content

Instantly share code, notes, and snippets.

@infinnie
Last active May 24, 2018 02:43
Show Gist options
  • Save infinnie/2d0a5e93d325409cd7f56db45499de2b to your computer and use it in GitHub Desktop.
Save infinnie/2d0a5e93d325409cd7f56db45499de2b to your computer and use it in GitHub Desktop.
Make arrays and functions flat.
var some = function (x) {
if (Array.isArray(x)) {
return [].concat.apply([], x.map(some));
}
if (typeof x === "function") {
return some(x());
}
return x;
};
some([function () {
return [1];
}, 2, [3], function () {
return 4;
}, [5, [6]]]); // [1, 2, 3, 4, 5, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment