I\'ve got this recursive generator
You could reduce array to generator. But this looks worse than for loop to me (though is functional :) )
var obj = [1, 2, 3, [4, 5, [6, 7, 8], 9], 10]
function* flat(x) {
if (Array.isArray(x))
yield * x.reduceRight(
(f, y) => function*() {
yield * flat(y);
yield * f()
},
function*() {}
)()
else
yield 'foo' + x;
}
console.log([...flat(obj)])