Today’s function is array.flatMap(), mdn description here.
FlatMap does two things:
- map() -> applies the test function to each element of the aray
- flat() -> flattens the results, i.e. smooshes together any nested arrays into a new single level 'flat' array.
That's right, it's the same as doing array.map.flat(). So why use it? It's a bit more efficient.
I've done my own version of the docs with sketches together. Here’s the folder for array.flatMap. Check out the readme to see how you can run the examples.
Top comments (0)