I have below two objects and i need to compare values
object with points
object based on the given answer like ‘Q1A1’ or ‘Q2A1’ and once key match in both object then it should return the sum of their respective answers.
const values = {
Q1: {
Q1A1: "Yes",
},
Q2: {
Q2A1: "Yes",
},
Q3: {
Q3A2: "No",
},
};
const points = {
Q1A1: 41,
Q1A2: 0,
Q2A1: 19,
Q2A2: 0,
Q3A1: 25,
Q3A2: 0,
};
After comparing both above object based on the given answer the sum will be 60. So, how can i return the sum 60 by comparing these object ?
4
Answers
You need to loop your answers. I would suggest using
true
/false
instead ofYes
/No
:This can be done in multiple ways. Here is one :
Use the values to drive the script:
Or (easier to read) make a lookup table and filter+reduce
you can try this: