function solution(dartResult) {
let roundScore = [];
let regEx = /\d+[SDT][#*]?/g
let score = dartResult.match(regEx)
score.forEach((a,i) => {
if(a.includes(10)) {
if(a.includes('S')) {
roundScore.push(10)
} else if(a.includes('D')) {
roundScore.push(10 ** 2)
} else if(a.includes('T')) {
roundScore.push(10 ** 3)
}
} else {
if(a.includes('S')) {
roundScore.push(a[0] ** 1)
} else if(a.includes('D')) {
roundScore.push(a[0] ** 2)
} else if(a.includes('T')) {
roundScore.push(a[0] ** 3)
}
}
if(a.includes('*')) {
if(roundScore[i-1] === undefined) {
roundScore[i] *= 2;
} else {
roundScore[i-1] *= 2;
roundScore[i] *= 2;
}
} else if (a.includes('#')) {
roundScore[i] *= -1;
}
})
return roundScore.reduce((acc,e) => acc+e,0)
}
모든 경우의 수를 고려하여 수를 대입하여 푸는 방법..
심플하고 깔끔하게 풀려고 몇시간을 고민해봐도 답이 안나와서 화가난다.