Skip to content

Commit a75efdf

Browse files
committed
[guide] improve ++/-- example.
Fixes airbnb#1130.
1 parent baa831b commit a75efdf

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,24 +1521,28 @@ Other Style Guides
15211521

15221522
let array = [1, 2, 3];
15231523
let num = 1;
1524-
let increment = num ++;
1525-
let decrement = -- num;
1524+
num ++;
1525+
-- num;
15261526

1527+
let sum = 0;
1528+
let truthyCount = 0;
15271529
for(let i = 0; i < array.length; i++){
15281530
let value = array[i];
1529-
++value;
1531+
sum += value;
1532+
if (value) {
1533+
truthyCount++;
1534+
}
15301535
}
15311536

15321537
// good
15331538

15341539
let array = [1, 2, 3];
15351540
let num = 1;
1536-
let increment = num += 1;
1537-
let decrement = num -= 1;
1541+
num += 1;
1542+
num -= 1;
15381543

1539-
array.forEach((value) => {
1540-
value += 1;
1541-
});
1544+
const sum = array.reduce((a, b) => a + b, 0);
1545+
const truthyCount = array.filter(Boolean).length;
15421546
```
15431547
15441548
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)