Hello all can somebody help me I don't know even where to start, little help is great. I have object like this
const Questions = {
five: "c"
four: "c"
one: "a"
three: "a"
two: "a"
};
And I have some object like this
const Answers = {
five: "a"
four: "a"
one: "a"
three: "a"
two: "a"
};
I need to compare these two objects and see if there are 3 or more matches correct, and based on that to show a different message. I know I can compare two objects like this
JSON.stringify(Questions) === JSON.stringify(Answers);
It will return me just true or false, I have tried also to return just corrected answer but again I had no luck, something like this
checkCorrectAnswers(obj1: any, obj2: any): any {
const keys1 = [];
const values1 = [];
Object.keys(obj1).forEach((element) => {
keys1.push(element);
});
Object.values(obj1).forEach((element) => {
values1.push(element);
});
const keys2 = [];
const values2 = [];
Object.keys(obj2).forEach((element) => {
keys2.push(element);
});
Object.values(obj2).forEach((element) => {
values2.push(element);
});
const obj = {};
keys1.forEach((element, i) => {
for (let index = 0; index < keys2.length; index++) {
if (element === keys2[index]) {
if (values1[i] !== values2[index]) {
const jsonKey = element;
obj[jsonKey] = values1[i];
}
break;
}
}
});
return obj;
}
Thanks again on the answer.