I'm struggling with the specific iteration logic required here. The object structure is somewhat complex:
var answers = {
cat1: {
q1: {
"question": "Why?",
"answer": "No",
"points": 6
},
q2: {
"question": "Why oh why?",
"answer": "50%",
"points": 15
},
q3: {
"question": "Is it true?",
"answer": "Maybe",
"points": 9
}
},
cat2: {
q1: {
"question": "Hello?",
"answer": "Hello",
"points": 0
},
q2: {
"question": "Why me?",
"answer": "Because",
"points": 9
},
q3: {
"question": "Is it true?",
"answer": "Maybe",
"points": 0
}
},
cat3: {
q1: {
"question": "why not?",
"answer": "I don't know",
"points": 15
},
q2: {
"question": "What?",
"answer": "That",
"points": 9
},
q3: {
"question": "Is it real?",
"answer": "Nope",
"points": 6
}
}
}
I need to find the highest points for each category's nested objects, excluding values of 15. Then, I want to add these high scores together.
It seems like using underscore.js could simplify this process by filtering out properties with a value of 15 and then using the _.max()
function to determine the highest points for each nested object before summing them up.
For example, in this case, the sum would be 9 + 9 + 9 (27).
If you have any insights or suggestions, I'd greatly appreciate your help!