Skip to content

Instantly share code, notes, and snippets.

@anthony2025
Last active October 25, 2016 05:10
Show Gist options
  • Save anthony2025/388a3c37e525bfd8bbe8 to your computer and use it in GitHub Desktop.
Save anthony2025/388a3c37e525bfd8bbe8 to your computer and use it in GitHub Desktop.
function romanizer(num) {
var result = '';
var decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
var roman = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
for (var i = 0; i < decimals.length; i++) {
while (num >= decimals[i]) {
result += roman[i];
num -= decimals[i];
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment