Two nifty-little-tricks I use regularly are Python’s built-in functions:
Both accept an iterable and return
True if any/all element/s of the iterable are true, ‘False’ otherwise.
Today I learned their JS equivalent for arrays:
The function checks whether at least one/every element in the array passes the condition implemented by the provided callback.
[10, 11, 12, 13].every((x) => x > 10); // false
[8, 9, 10, 11].some((x) => x > 10); // true
- The 2nd callback parameter (optional) is the element index
- The 3rd (optional as well) is the array called