Earlier quoted context omitted.
You could do that, but I’d argue using filter then map is more readable. What do empty arrays have to do with doubling even integers?
The interesting generalization is that once you realize that flatMap lets you map and filter at the same time is that you can generate arbitrary elements in the output list corresponding to each item in the input list. For example, ls.flatMap(x => { if (x gives you all the real square roots from the original list, doing the mapping, flattening, and filtering all in one function call.
ls.filter(o=>0o||[Math.sqrt(x, -Math.sqrt(x)])