Hard
This question is a daily question and will count towards your daily streak.
In a web analytics tool, you need to track user interactions. What will be logged after these interactions are processed?
1class EventTracker {2 static processEvents(events) {3 return events.reduce((summary, event) => {4 const { type, duration } = event;56 if (!summary[type]) {7 summary[type] = {8 count: 0,9 totalDuration: 0,10 avgDuration: 011 };12 }1314 summary[type].count++;15 summary[type].totalDuration += duration;16 summary[type].avgDuration = Math.round(17 summary[type].totalDuration / summary[type].count18 );1920 return summary;21 }, {});22 }23}2425const events = [26 { type: 'click', duration: 100 },27 { type: 'scroll', duration: 150 },28 { type: 'click', duration: 200 },29 { type: 'scroll', duration: 250 }30];3132console.log(EventTracker.processEvents(events));