250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

devlog_owen

[프로그래머스] DAY4 배열의 평균값 본문

algorithm/(js)프로그래머스

[프로그래머스] DAY4 배열의 평균값

developer_owen 2023. 10. 24. 10:58
728x90

내가 쓴 풀이

 

function solution(numbers) {
 const sum = numbers.reduce((a,b) => a+b,0)
       
return(sum/numbers.length);
}

reduce 메서드를 쓰는게 관건인 문제같다. 마지막에 리턴을 안하고 console.log로 하느라 헤맸다. 

 

다른사람 풀이

function solution(numbers) {
    var answer = numbers.reduce((a,b) => a+b, 0) / numbers.length;
    return answer;
}

내 풀이와 비슷하다. 이게 좀더 깔끔한 거 같다. 

728x90