https://programmers.co.kr/learn/courses/30/lessons/17682
const solution = dartResult => {
let temp = 0;
let answer = [];
let sum = 0;
for(let i = 0; i < dartResult.length; i++) {
if(dartResult[i] >= 0 && dartResult[i] <= 9) {
if(dartResult[i] == 1 && dartResult[i+1] == 0) {
temp = 10;
i++;
} else {
temp = dartResult[i];
}
}
else if(dartResult[i] === 'S') {
answer.push(temp);
}
else if(dartResult[i] === 'D') {
answer.push(Math.pow(temp, 2));
}
else if(dartResult[i] === 'T'){
answer.push(Math.pow(temp, 3));
}
else if(dartResult[i] == '#') {
answer[answer.length-1] *= -1;
}
else if(dartResult[i] == '*') {
answer[answer.length-1] *= 2;
answer[answer.length-2] *= 2;
}
}
for(let j = 0; j < answer.length; j++) {
sum += Number(answer[j]);
}
return sum;
}
거듭제곱 구할 때
1. Math.pow(number, 2);
2. number **= 2;
포인트 ① 0~9일 경우와 10일 경우 분리!