September 2017
Intermediate to advanced
216 pages
6h 8m
English
An example of where mapping and filtering collections would be insufficient is finding minimum and maximum values. Let's implement some reducers to find these values in a collection:
const myList = List.of( Map.of('red', 3, 'black', 4), Map.of('red', 6, 'black', 8), Map.of('red', 9, 'black', 12));const minRedReduce = myList.reduce( (result, v) => v.get('red') < result ? v.get('red') : result, myList.first().get('red'));const maxRedReduce = myList.reduce( (result, v) => v.get('red') > result ? v.get('red') : result, myList.first().get('red'));console.log('minRedReduce', minRedReduce);// -> minRedReduce 3console.log('maxRedReduce', maxRedReduce);// -> maxRedReduce 9
The result argument that's passed to the iteratee ...
Read now
Unlock full access