Skip to content

Commit 00f2072

Browse files
Merge pull request ryanmcdermott#234 from valtism/master
Change complex reduce code sample to clearer map reduce.
2 parents 6741e85 + eb364be commit 00f2072

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ class SuperArray extends Array {
659659

660660
### Favor functional programming over imperative programming
661661
JavaScript isn't a functional language in the way that Haskell is, but it has
662-
a functional flavor to it. Functional languages are cleaner and easier to test.
662+
a functional flavor to it. Functional languages can be cleaner and easier to test.
663663
Favor this style of programming when you can.
664664

665665
**Bad:**
@@ -705,10 +705,9 @@ const programmerOutput = [
705705
}
706706
];
707707

708-
const INITIAL_VALUE = 0;
709-
710708
const totalOutput = programmerOutput
711-
.reduce((acc, { linesOfCode }) => acc + linesOfCode, INITIAL_VALUE);
709+
.map(output => output.linesOfCode)
710+
.reduce((totalLines, lines) => totalLines + lines);
712711
```
713712
**[⬆ back to top](#table-of-contents)**
714713

0 commit comments

Comments
 (0)