I have two sets of data. I am looking to calculate the total time_spent for each course_id that appears in both set 1 and set 2.
let set1 = [
{ instructor_id: 7, course_id: 19, lesson_id: 1, time_spent: 0 },
{ instructor_id: 7, course_id: 19, lesson_id: 2, time_spent: 0 },
{ instructor_id: 7, course_id: 19, lesson_id: 3, time_spent: 0 },
{ instructor_id: 7, course_id: 20, lesson_id: 4, time_spent: 80 },
{ instructor_id: 7, course_id: 20, lesson_id: 5, time_spent: 40 },
{ instructor_id: 8, course_id: 21, lesson_id: 6, time_spent: 0 },
];
let set2 = [
{ id: 19, title: "Course 19", duration: 180 },
{ id: 20, title: "Course 20", duration: 120 },
];
// expected output
newSet = [
{ instructor_id: 7, course_id: 19, time_spent: 0 },
{ instructor_id: 7, course_id: 20, time_spent: 120 },
];