Created
January 26, 2017 21:03
-
-
Save 7LayersDesign/524a4ce2a276b68395c92cb5c36cf4b0 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
var out = document.getElementById('out'); | |
for ( var i=1 ; i <=100 ; ++i ) { out.innerHTML+= i+"\t"+romanize(i)+"<br/>"; } | |
function romanize(num) { | |
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 ( num >= lookup[i] ) { | |
roman += i; | |
num -= lookup[i]; | |
} | |
} | |
return roman; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment