Iterators and Generators: sum should be 15, not 10

This commit is contained in:
Casey Jenks
2015-04-02 21:41:11 -04:00
committed by Josh Perez
parent 58cdc731f4
commit b8fd0438fb

View File

@@ -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.