-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm37.js
More file actions
42 lines (42 loc) · 1.05 KB
/
algorithm37.js
File metadata and controls
42 lines (42 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function solution(dartResult) {
var answer = 0;
let div_list = [];
let bef = 0
let temp = ''
dartResult.split("").map((v, i) => {
if(!isNaN(v) && isNaN(bef)){
div_list.push(temp)
temp = v
bef = v
} else {
temp += v
bef = v
}
})
div_list.push(temp)
let res = []
for(let i=0; i<div_list.length; i++){
let num = ''
let pow = 0
let spc = 1
div_list[i].split("").map((v, j) => {
if(!isNaN(v)){
num += v
} else {
if(v === "S"){pow = 1}
if(v === "D"){pow = 2}
if(v === "T"){pow = 3}
if(v === "*"){
spc = spc * 2
if(i !== 0){
res[i-1] = res[i-1] * 2
}
}
if(v === "#"){spc = -1}
}
})
res.push(Number(num) ** pow * spc)
}
answer=(res.reduce((e, c) => e + c))
return answer;
}