Created
October 17, 2021 18:55
-
-
Save lior-amsalem/63b7841dc5f9b9533ed0295d87332523 to your computer and use it in GitHub Desktop.
Roman Numerals Decoder
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
/** | |
solution('XXI'); // should return 21 | |
**/ | |
const helper = { | |
'I': 1, | |
'V': 5, | |
'X': 10, | |
'L': 50, | |
'C': 100, | |
'D': 500, | |
'M': 1000 | |
} | |
function solution(roman){ | |
return roman.split('').map(a => helper[a]).reduce((a,b) => (a >= b) ? (a + b) : (b - a)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment