getTotalUserVotes = (userid) => {
let posts = this.state.posts.slice();
let current = posts.filter((item) => {
return item.userid === userid;
})
console.log(current);
const tot = current.map((item) => {
return item.votes;
})
console.log("tot is " + tot)
// this logs 50, 0 ,0
//so each of the three posts that belong to that user have those amount
//of votes respectively.How can I add these?
return <div>votes: {tot}</div>;
}
When I have tried adding these using a for loop the strings concatenate so ill get 5000, I have searched how to stop that on stack overflow but none of the answers had little to any relation to my circumstance. somewhat related question.
an example of the data in posts is here