Last active
September 16, 2017 06:45
-
-
Save rosd89/67529e952f40105c6c84085839e4d81e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(dartResult) { | |
const answer = dartResult.match(/(\d+|\D)/g).reduce((p, c) => { | |
let n = 0; | |
switch(c) { | |
case '*' : | |
const n1 = p.pop(); | |
const n2 = p.pop(); | |
if(n2) p.push(n2 * 2); | |
p.push(n1 * 2); | |
break; | |
case '#' : | |
n = p.pop(); | |
p.push(n * -1); | |
break; | |
case 'S' : | |
break; | |
case 'D' : | |
n = p.pop(); | |
p.push(n * n); | |
break; | |
case 'T' : | |
n = p.pop(); | |
p.push(n * n * n); | |
break; | |
default: | |
p.push(+c); | |
} | |
return p; | |
}, []); | |
return answer.reduce((p, c) => p + c, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment