23 ms·
Doesn't the fact that flatten by default only flattens one level mean you can still create nested output by emitted nested outputs?
by ajanuary 7y ago
Doesn't the fact that flatten by default only flattens one level mean you can still create nested output by emitted nested outputs?
- 2T1Qka0rEiPr 7y agoYes, it appears so. From MDN: > The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is identical to a map() followed by a flat() of depth 1, but flatMap() is often quite useful, as merging both into one method is slightly more efficient. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- swish_bob 7y agoFlatMap is often most useful when recursing, in my experience.
- ohaideredevs 7y agoI have used recursion two times irl outside of interviews.
- swish_bob 7y agoUsed with flatMap, it's a terribly good way of doing something to everything over an arbitrary object and all it's deep values. I do something like this every month or so. It's one of those tricks you use a lot once you've seen the problems it's applicable to.