I have two arrays. They are always the same length. If userEmotions[index] value is true I need to add userTimeData[index] value to a variable:
var userEmotions = [false, true, false, true],
userTimeData = [140, 320, 730, 50],
userPercentage = 0;
// e.g add 320 and 50 to userPercentage:
// userPercentage == 370
How do I go about achieving this?
for (index in userEmotions) { if (userEmotions[index]) { userPercentage += userTimeData[index]; } }. Not enough to compute a percentage, but you can use it as a starting point.userPercentage = userEmotions.reduce((sum, e, i) => sum + (e && userTimeData[i]), 0)