function solution20(arr) {
return arr.reduce((acc, curr) => acc + curr) / arr.length;
}
console.log(solution20([1, 2, 3, 4])); // 2.5
console.log(solution20([5, 5])); // 5
function solution21(arr) {
let avg = 0;
for (let i = 0; i < arr.length; i++) {
avg += arr[i] / arr.length;
}
return avg;
}
console.log(solution21([1, 2, 3, 4])); // 2.5
console.log(solution21([5, 5])); // 5