mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 04:48:12 -05:00
Iterators and Generators: sum should be 15, not 10
This commit is contained in:
@@ -786,16 +786,16 @@
|
||||
sum += num;
|
||||
}
|
||||
|
||||
sum === 10;
|
||||
sum === 15;
|
||||
|
||||
// good
|
||||
let sum = 0;
|
||||
numbers.forEach((num) => sum += num);
|
||||
sum === 10;
|
||||
sum === 15;
|
||||
|
||||
// best (use the functional force)
|
||||
const sum = numbers.reduce((total, num) => total + num, 0);
|
||||
sum === 10;
|
||||
sum === 15;
|
||||
```
|
||||
|
||||
- Don't use generators.
|
||||
|
||||
Reference in New Issue
Block a user