Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. var characters = [
  2. {
  3. key: 'I',
  4. value: 1
  5. },
  6. {
  7. key: 'V',
  8. value: 5
  9. },
  10. {
  11. key: 'X',
  12. value: 10    },
  13. {
  14. key: 'L',
  15. value: 50
  16. },
  17. {
  18. key: 'C',
  19. value: 100
  20. },
  21. {
  22. key: 'D',
  23. value: 500
  24. },
  25. key: 'M',
  26. value: 1000
  27. }];
  28. (function () {
  29. characters = characters.sort((a, b) => {
  30. if(a.value > b.value) {
  31. return 1;
  32. }
  33. if (a.value < b.value) {
  34. return -1;
  35. }
  36. return 0;
  37. });
  38. var number = parseInt(process.argv[2]);
  39. var output = "";
  40. while(number !== 0)
  41. for(var i = characters.length - 1; i >= 0; i--)
  42. if (number >= characters[i].value) {
  43. output += characters[i].key;
  44. number -= characters[i].value;
  45. break;
  46. }
  47. console.log(output);
  48. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement