Skip to content

Instantly share code, notes, and snippets.

@kav2k
Last active January 11, 2016 16:07
Show Gist options
  • Save kav2k/8504d18c64ea66fbbd86 to your computer and use it in GitHub Desktop.
Save kav2k/8504d18c64ea66fbbd86 to your computer and use it in GitHub Desktop.
// April Fools '11
// From dA Message Notifier
function romanize(input) {
var output = input;
output = output.toUpperCase();
output = output.replace(/J/g,'I');
output = output.replace(/U/g,'V');
//output = output.replace(/W/g,'VV');
output = output.replace(/([0-9]+)/g, romanNumeral);
return output;
}
function romanNumeral(decimal) {
var lookup = {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},
roman = '',
i;
for ( i in lookup ) {
while ( decimal >= lookup[i] ) {
roman += i;
decimal -= lookup[i];
}
}
return roman;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment