gpt4 book ai didi

javascript - 测验中平均回答正确的问题数

转载 作者:行者123 更新时间:2023-11-30 19:54:35 24 4
gpt4 key购买 nike

我有一个问 3 个问题的测验应用程序。随着时间的推移,我跟踪正确/错误的答案如下:

var c0 = 143; // Number of users who got 0 questions correct
var c1 = 278; // Number of users who got 1 question correct
var c2 = 236; // Number of users who got 2 questions correct
var c3 = 185; // Number of users who got 3 questions correct

如何计算用户答对的平均题数?

var averageCorrectQuestions = 2.15; // Example (out of 3)

最佳答案

您可以将计数乘以正确问题的计数,将此值相加并计算所有用户。结果是将总和除以计数。

var c0 = 143,
c1 = 278,
c2 = 236,
c3 = 185,
[sum, count] = [c0, c1, c2, c3].reduce(([s, c], n, v) => [s + n * v, c + n], [0, 0]);

console.log(sum, count);
console.log(sum/count);

关于javascript - 测验中平均回答正确的问题数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54142949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com