Created
April 2, 2019 16:11
-
-
Save bmansk8/703d87dda1d5cf169fc203fc07851b3e to your computer and use it in GitHub Desktop.
This file contains 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
function convertToRoman(num) { | |
var roman=""; | |
var romanNumeral=['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; | |
var numbers=[1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; | |
for(var i=0;i<numbers.length;i++){ | |
while(num>=numbers[i]){ | |
roman = roman + romanNumeral[i]; | |
num = num - numbers[i]; | |
} | |
} | |
return roman; | |
} | |
convertToRoman(36); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment