User avatar
Volpeon
@volpeon@icy.wyvern.rip
Nice immutability you got there

(
github.com/airbnb/javascript?tab=readme-ov-file#iterators-and-generators )
11.1 Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like for-in or for-of. eslint: no-iterator no-restricted-syntax

- Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.

- Use map() / every() / filter() / find() / findIndex() / reduce() / some() / ... to iterate over arrays, and Object.keys() / Object.values() / Object.entries() to produce arrays so you can iterate over objects.

```
const numbers = [1, 2, 3, 4, 5];

// bad
let sum = 0;
for (let num of numbers) {
  sum += num;
}
sum === 15;

// good
let sum = 0;
numbers.forEach((num) => {
  sum += num;
});
sum === 15;
```