Last active
October 11, 2018 18:31
-
-
Save peebeebee/7962113b4ea5242888a57f26428b9ce0 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
const roman = 'XXVIV'; | |
const mapping = {'X': 10, 'I': 1, 'V': 5}; // add stuff | |
const total = roman.split('').map(el => mapping[el]).reduce((acc, curr, i, src) => { | |
let prev = src[i-1]; | |
return (prev && curr > prev) | |
? acc - prev + (curr-prev) | |
: acc + curr; | |
}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment