[JS] 1546번 - 평균

박세현·2021년 5월 23일
0

알고리즘

목록 보기
6/19

평균

문제 출처

https://www.acmicpc.net/problem/1546


key point


Math.max(1,2,3,4,5); // 5

//
fn.apply(thisArg, [argsArray])
Math.max.apply(null, [1,2,3,4,5]) // 5

풀이

점수중 최대값 M을 구하는 방법으로 Math.max 메소드와 apply 메소드를 사용해서 구할 수 있다.

let input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');

const scoreArr = input[1].split(' ').map((x) => Number(x));
const max = Math.max.apply(null, scoreArr);

let sum = 0;
scoreArr.map((score) => {
   sum += (score / max * 100);
});

console.log(sum / scoreArr.length);

profile
Front End 공부노트

0개의 댓글

관련 채용 정보