Created
November 20, 2015 06:16
-
-
Save minsooshin/ee0a41410e4fcdab965c 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
// Bonfire: Roman Numeral Converter | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function convert(num) { | |
var romanMap = { | |
"M": 1000, | |
"CM": 900, | |
"D": 500, | |
"CD": 400, | |
"C": 100, | |
"XC": 90, | |
"L": 50, | |
"XL": 40, | |
"X": 10, | |
"IX": 9, | |
"V": 5, | |
"IV": 4, | |
"I": 1 | |
}, | |
romanStr = ''; | |
for (var key in romanMap) { | |
while (num >= romanMap[key]) { | |
romanStr += key; | |
num -= romanMap[key]; | |
} | |
} | |
return romanStr; | |
} | |
convert(36); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment