[javascript] I don't know if I missed something

thanks for reading :sweat_smile:
I want to deliver the function, but I have an error.

const people = [{
        name: "John Doe",
        age: 16
    },
    {
        name: "Thomas Calls",
        age: 19
    },
    {
        name: "Liam Smith",
        age: 20
    },
    {
        name: "Jessy Pinkman",
        age: 18
    },
];
const coffeeLovers = ["John Doe", "Liam Smith", "Jessy Pinkman"];
const ageReducer = ((sum, person) => sum + person.age, 0);
// coffeeLoversAbove18 : collection
const totalAgeOfCoffeeLoversAbove18 = coffeeLoversAbove18
    .reduce(ageReducer); //Uncaught TypeError ??
// ok ..
const totalAgeOfCoffeeLoversAbove18 = coffeeLoversAbove18
    .reduce((sum, person) => {
        return sum + person.age;
    }, 0);

First of all, what you do mean by “deliver the function”.

Second, what is the error?

Third, what are you trying to accomplish here with this code?

This variable is not defined anywhere and you are trying to use reduce on it

Thanks for your help.

I’d like to get the total age of coffee lovers.
but
ex) redcue(func) This results in an error.

If you are trying to get the sum of all the ages of people who are coffee lovers and are over 18, then the following would do that:

const people = [{
        name: "John Doe",
        age: 16
    },
    {
        name: "Thomas Calls",
        age: 19
    },
    {
        name: "Liam Smith",
        age: 20
    },
    {
        name: "Jessy Pinkman",
        age: 18
    },
];
const coffeeLovers = ["John Doe", "Liam Smith", "Jessy Pinkman"];
const totalAgeOfCoffeeLoversAbove18 = people.reduce((sum, person) => {
  if (coffeeLovers.includes(person.name) && person.age > 18) {
    sum += person.age;
  }
  return sum;
}, 0);

Thank you again, sir.

As you mentioned, the problem was solved.:smiling_face_with_three_hearts: