Skip to content

Instantly share code, notes, and snippets.

@lior-amsalem
Created October 17, 2021 18:55
Show Gist options
  • Save lior-amsalem/63b7841dc5f9b9533ed0295d87332523 to your computer and use it in GitHub Desktop.
Save lior-amsalem/63b7841dc5f9b9533ed0295d87332523 to your computer and use it in GitHub Desktop.
Roman Numerals Decoder
/**
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