Last active
March 30, 2017 15:10
-
-
Save Xmerr/2a056cc9d7861d0123e4b3d000a9b2ac 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 characters = [ | |
{ | |
key: 'I', | |
value: 1 | |
}, | |
{ | |
key: 'V', | |
value: 5 | |
}, | |
{ | |
key: 'X', | |
value: 10 }, | |
{ | |
key: 'L', | |
value: 50 | |
}, | |
{ | |
key: 'C', | |
value: 100 | |
}, | |
{ | |
key: 'D', | |
value: 500 | |
}, | |
{ | |
key: 'M', | |
value: 1000 | |
}]; | |
(function () { | |
characters = characters.sort((a, b) => { | |
if(a.value > b.value) { | |
return 1; | |
} | |
if (a.value < b.value) { | |
return -1; | |
} | |
return 0; | |
}); | |
var number = parseInt(process.argv[2]); | |
var output = ""; | |
while(number !== 0) | |
for(var i = characters.length - 1; i >= 0; i--) | |
if (number >= characters[i].value) { | |
output += characters[i].key; | |
number -= characters[i].value; | |
break; | |
} | |
console.log(output); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment