문제
풀이 과정
const solutionA = (dartResult) => {
const answer = [];
let result = 0;
for (let i = 0; i < dartResult.length; i++) {
const dart = dartResult[i];
if (!isNaN(dart)) {
if (dart == 1 && dartResult[i + 1] == 0) {
result = 10;
i++;
} else result = parseInt(dart);
}
if (dart === 'S') answer.push(Math.pow(result, 1));
else if (dart === 'D') answer.push(Math.pow(result, 2));
else if (dart === 'T') answer.push(Math.pow(result, 3));
else if (dart === '*') {
answer[answer.length - 1] *= 2;
answer[answer.length - 2] *= 2;
} else if (dart === '#') answer[answer.length - 1] *= -1;
}
return answer.reduce((acc, cur) => acc + cur, 0);
};
const testA = solutionA('1S2D*3T');
console.log(testA);
틀린 부분이 있거나 보충해야 할 내용이 있다면 댓글이나 DM(sungstonemin)으로 알려주시면 감사하겠습니다😄