문제
풀이
function solution(dartResult) {
let num = 0;
let ans = [];
let temp = 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") {
ans.push(temp);
} else if (dartResult[i] === "D") {
ans.push(temp ** 2);
} else if (dartResult[i] === "T") {
ans.push(temp ** 3);
} else if (dartResult[i] == "#") {
ans[ans.length - 1] *= -1;
} else if (dartResult[i] == "*") {
ans[ans.length - 1] *= 2;
ans[ans.length - 2] *= 2;
}
}
for (let i = 0; i < ans.length; i++) {
num += Number(ans[i]);
}
return num;
}