function calAVG(array, interval){
if(!(Array.isArray(array))) throw '参数异常'
for(let ele of array){
if(isNaN(parseFloat(ele))){
throw '数组中有不能转换为数字的元素'
}
}
const result = [],
INTERVAL = interval || 1,
reducer = (accumulator, currentValue) => accumulator + currentValue;
let arrayLength = array.length;
if(arrayLength <= interval){
console.info(array.reduce(reducer))
result.push(array.reduce(reducer)/arrayLength);
return result;
}
for(let[index, value] of array.entries()){
let endIndex = index + INTERVAL,
currentArray = array.slice(index, endIndex + 1);
if(endIndex >= arrayLength){
result.push(currentArray.reduce(reducer)/(currentArray.length))
break;
}
result.push(currentArray.reduce(reducer)/(INTERVAL + 1));
}
return result;
}