字段值默认函数计算的代码到底是怎么样用,怎么改都不会输出值(求大神)

问答  收藏
2 / 57
function calculateAverageAndPrintPercentage(fieldValues) {
  if (!Array.isArray(fieldValues) || fieldValues.length === 0) {
    console.log("请输入有效的字段值数组。");
    return;
  }

  var total = fieldValues.reduce(function (sum, value) {
    return sum + value;
  }, 0);

  var average = total / fieldValues.length;

  var range = 0.05 * average;

  var lowerBound = average - range;
  var upperBound = average + range;

  if (average >= lowerBound && average <= upperBound) {
    console.log("平均值在5%的幅度内:" + average);
  } else {
    console.log("平均值超出5%的幅度:" + average);
  }

  // 打印输出百分比值
  console.log("平均值的百分比值:", (average / total) * 100 + "%");

  // 返回平均值
  return average;
}