Skip to content

Instantly share code, notes, and snippets.

@rosd89
Last active September 16, 2017 06:45
Show Gist options
  • Save rosd89/67529e952f40105c6c84085839e4d81e to your computer and use it in GitHub Desktop.
Save rosd89/67529e952f40105c6c84085839e4d81e to your computer and use it in GitHub Desktop.
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