Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement