We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a560deb commit 7dadd5dCopy full SHA for 7dadd5d
oh-chaeyeon/2주차_스택/Dart_Game.js
@@ -0,0 +1,24 @@
1
+function solution(dartResult) {
2
+ const stack = [];
3
+ let i = 0;
4
+
5
+ while (i < dartResult.length) {
6
+ const isTen = dartResult[i] === "1" && dartResult[i + 1] === "0";
7
+ let score = isTen ? 10 : parseInt(dartResult[i]);
8
+ i += isTen ? 2 : 1;
9
10
+ const bonus = dartResult[i++];
11
+ score **= bonus === "S" ? 1 : bonus === "D" ? 2 : 3;
12
13
+ if (dartResult[i] === "*" || dartResult[i] === "#") {
14
+ score *= dartResult[i] === "*" ? 2 : -1;
15
+ if (dartResult[i++] === "*" && stack.length) {
16
+ stack[stack.length - 1] *= 2;
17
+ }
18
19
20
+ stack.push(score);
21
22
23
+ return stack.reduce((sum, cur) => sum + cur, 0);
24
+}
0 commit comments