Javascript - Method Chaining
Code Life
By Pierre Marsaa
One Result Feeds the Next
A real task is rarely a single step. Here you have your team's levels. You only care about the high ones, and then you want to display them as labels like Lv.12. That's two operations one after the other: first select, then transform.
↗️
Loading editor...
↶
↷
The high variable is only used on the next line. You can skip it and call map directly on what filter returned. That's chaining:
↗️
Loading editor...
↶
↷
Because each of these methods returns an array, the result of the first can go straight into the second. It's not magic, it's code :)
Verify