Last active
May 24, 2018 02:43
-
-
Save infinnie/2d0a5e93d325409cd7f56db45499de2b to your computer and use it in GitHub Desktop.
Make arrays and functions flat.
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 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