I'm trying to learn array method chaining and am using a basic example - https://jsbin.com/surizinifi/edit?js,console
const data = [
{
name: 'Butters',
age: 3,
type: 'dog'
},
{
name: 'Lizzy',
age: 6,
type: 'dog'
},
{
name: 'Red',
age: 1,
type: 'cat'
},
{
name: 'Joey',
age: 3,
type: 'dog'
},
];
const ages = data
.filter(animal => animal.type === 'dog')
.map(animal => animal.age * 7)
.reduce((sum, animal) => sum + animal.age)
console.log('ages', ages);
I'm getting "NaN" returned as a posed to a numeric output (e.g. 84). Any ideas what I'm doing wrong here?
reduceyou don't gen ananimalobject butanimalAgenumber - themapfrom the previous step gives you an array of numbers.