[guide] improve ++/-- example.

Fixes #1130.
This commit is contained in:
Jordan Harband
2016-10-14 22:37:14 -07:00
parent baa831b4a9
commit a75efdfdb0

View File

@@ -1521,24 +1521,28 @@ Other Style Guides
let array = [1, 2, 3];
let num = 1;
let increment = num ++;
let decrement = -- num;
num ++;
-- num;
let sum = 0;
let truthyCount = 0;
for(let i = 0; i < array.length; i++){
let value = array[i];
++value;
sum += value;
if (value) {
truthyCount++;
}
}
// good
let array = [1, 2, 3];
let num = 1;
let increment = num += 1;
let decrement = num -= 1;
num += 1;
num -= 1;
array.forEach((value) => {
value += 1;
});
const sum = array.reduce((a, b) => a + b, 0);
const truthyCount = array.filter(Boolean).length;
```
**[⬆ back to top](#table-of-contents)**