Skip to content

Instantly share code, notes, and snippets.

@emayom
Last active August 26, 2021 06:25
Show Gist options
  • Save emayom/cf408aeb39336ca55688f7fd6c268dd8 to your computer and use it in GitHub Desktop.
Save emayom/cf408aeb39336ca55688f7fd6c268dd8 to your computer and use it in GitHub Desktop.
[프로그래머스] 위클리챌린지 2주차
function solution(sample) {
let scores = [];
let grades = "";
const S_LENGTH = sample.length;
function calc(index, score){
const MAX = Math.max(...score);
const MIN = Math.min(...score);
const SELF = score[index];
const cnt = score.filter(el => el == SELF).length;
let total = score.reduce((acc, cv) => acc + cv);
let average ;
if((SELF == MAX || SELF == MIN) && (cnt == 1)){
total -= SELF;
average = total / (S_LENGTH-1);
} else {
average = total / S_LENGTH;
}
switch(true){
case (average >= 90):
return "A";
case (average >= 80):
return "B";
case (average >= 70):
return "C";
case (average >= 50):
return "D";
case (average < 50):
return "F";
}
}
for(let i=0; i < S_LENGTH; i++){
const temp = [];
for(let j=0; j < S_LENGTH; j++){
temp.push(sample[j][i]);
}
scores.push(temp);
}
for(let i=0; i < S_LENGTH; i++){
grades += calc(i, scores[i]);
}
return grades;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment