that calculates the mean response times for each person in javascript

You can calculate the mean response times for each person in Javascript by following these steps:

Assuming you have an array of response times for each person, here's the code to calculate the mean response time for each person.

index.tsx
let responseTimes = [
    { name: "person1", times: [10, 15, 20, 25, 30] },
    { name: "person2", times: [20, 25, 30, 35, 40] },
    { name: "person3", times: [30, 35, 40, 45, 50] },
];

let meanResponseTimes = {};

responseTimes.forEach(person => {
    let sum = person.times.reduce((a, b) => a + b);
    let mean = sum / person.times.length;
    meanResponseTimes[person.name] = mean;
});

console.log(meanResponseTimes);
425 chars
16 lines

This will output an object containing the mean response time for each person:

index.tsx
{
    person1: 20,
    person2: 30,
    person3: 40
}
54 chars
6 lines

gistlibby LogSnag