Higher Order Functions: Using Filter, Map and Reduce for More Maintainable Code
Guido Schmitz
3.5K14

Wouldn’t your code just give you the sum of ages over 18? You are mapping a coffee lover property, but not filtering on it.

I think this:

const coffeeLoversAbove18 = people
.filter(ageAbove18)
.map(addCoffeeLoverProperty);

Should be this:

const coffeeLoversAbove18 = people
.filter(ageAbove18)
.map(addCoffeeLoverProperty)
.filter(p => p.coffeeLover);