So I got help with this IMMEDIATELY from StackOverflow and apparently I've been accused of farming reputation points for finally figuring out the answers to some of my previous questions and then adding the answer in after it being posted here for hours. So, if someone wants to solve this roblem using the .reduce method instead of the .forEach method I'll mark you as the top answer/whatever.
Example:
let ppl = [{name: "Anthony", score: 10},
{name: "Fred", score : 10},
{name: "Anthony", score: -8},
{name: "Winnie", score: 12}];
console.log(countScores(ppl));
Sounds silly, but I am at a loss as to how to keep track of the scores through iterations here. I either end up getting NaN even when converting --->
score = (person[key])
when I add it to score in the Object it givs me some realy weird results.
+ expected - actual
{
- "Anthony": -8
+ "Anthony": 2
"Fred": 10
"Winnie": 12
}
What I have tried:
function countScores(people) {
let scoreCount = {};
people.forEach(person => { let score = 0;
score += person.score; name = person.name;
scoreCount[name] = score;
})
console.log(scoreCount)
console.log("Endig Calculation of Scores....")
return scoreCount;
};