Tell us what’s happening:
I don’t understand how this reduce works. It’s really confusing to me because in the example given below, we are using the reduce method, and having arguments of a function with arguments of sum and user??? Then we define the function, saying to return sum + user.age??? I’m really confused because we never even defined the variable user, so how can we even provide a value for user.age? How does this function know that the user is even an object/array?
Your code so far
function getRating(watchList){
// Only change code below this line
var averageRating;
const users = [
{ name: ‘John’, age: 34 },
{ name: ‘Amy’, age: 20 },
{ name: ‘camperCat’, age: 10 }
];
const sumOfAges = users.reduce((sum, user) => sum + user.age, 0);
console.log(sumOfAges); // 64
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
.
Challenge: Use the reduce Method to Analyze Data
Link to the challenge: