```javascript## 标题有三个班级每个班级有十人求他们的平均分和平均分最高的班级
oneClass = [50, 89, 78, 45, 68, 45, 28, 48, 94, 85];
twoClass = [15, 49, 65, 48, 78, 64, 84, 43, 95, 49];
threeClass = [68, 75, 48, 95, 85, 67, 45, 35, 85, 45];
//求平均分
function Arr(m, n) {
return m + n;
}
oneClassAvg = oneClass.reduce(Arr) / 10;
twoClassAvg = twoClass.reduce(Arr) / 10;
threeClassAvg = threeClass.reduce(Arr) / 10;
// alert(oneClassAvg);
//求最大值
var sumClassAvg = [];
sumClassAvg.unshift(oneClassAvg, twoClassAvg, threeClassAvg);
// alert(sumClassAvg);
var maxIndex = 0;
for (var i = 1; i < sumClassAvg.length; i++) {
if (sumClassAvg[i] > sumClassAvg[maxIndex]) {
maxIndex = i;
}
}
var maxClass = "";
//找出最大值班级
if (maxIndex == 0) {
maxClass = "一班"
}
if (maxIndex == 1) {
maxClass = "二班"
}
if (maxIndex == 2) {
maxClass = "三班"
}
alert("一班平均分为" + oneClassAvg + "\n" + "二班平均分为" + twoClassAvg + "\n" + "三班平均分为" + threeClassAvg + "\n" + maxClass +
"是优秀班级,平均分为" + sumClassAvg[maxIndex]);`在这里插入代码片`