我试图从数组中排除“ 0”值,以获得更好的平均结果。
我的数组是:[0,0,0,0,80,90,100,0]
function clacGPA(gradeData) {
var sum, avg = 0;
if (gradeData.length) {
sum = gradeData.reduce(function (a, b) {
return a + b;
});
avg = sum / gradeData.length;
}
document.getElementById('gpa').innerText = avg.toFixed(2);
}
My expected result should be:
avg = 80+90+100 / 3
catspeake
守着星空守着你
相关分类