June 2018
Beginner
288 pages
6h 31m
English
Here are the solutions to the Exercises, for the Chapter 8, Using Inheritance chapter.
| | 'use strict'; |
| | |
| | class FunctionalSet extends Set { |
| | filter(predicate) { |
| | return new FunctionalSet([...this].filter(predicate)); |
| | } |
| | |
| | map(mapper) { |
| | return new FunctionalSet([...this].map(mapper)); |
| | } |
| | reduce(accumulator, identity) { |
| | return [...this].reduce(accumulator, identity); |
| | } |
| | } |
| | |
| | const set = new FunctionalSet(['Jack', 'Jill', 'Tom', 'Jerry']); |
| | |
| | const jSet = set.filter(name => name.startsWith('J')); |
| | const allCaps = set.map(name => name.toUpperCase()); |
| | |
| | const totalLengthOfJWords = |
| | set.filter(name => name.startsWith('J')) |
| | .reduce((total, word) => total + word.length, ... |
Read now
Unlock full access