https://programmers.co.kr/learn/courses/30/lessons/12944
function solution(arr) {
var answer = 0;
var temp = 0;
var length = arr.length;
arr.forEach(num=>{temp = temp+num;});
answer = temp / length;
return answer;
}
reduce 사용해서 다시 풀어보기
function solution(arr) {
var answer = 0;
var length = arr.length;
answer = arr.reduce((acc, cur) => acc+cur) / length;
return answer;
}
function solution(arr) {
var answer = 0;
var sum = 0;
var lengthOfArray = arr.length;
for (var i=0; i<lengthOfArray; i++){
sum = sum + arr[i];
}
answer = sum / lengthOfArray;
return answer;
}
array method - reduce