To run romanNumerals.js itself:
node romanNumerals.jsYou might want to run
romanNumerals.jsitself so you can put in print statements and use a single test example while debugging
To run romanNumeralsSpec.js:
node romanNumeralsSpec.jsWe want to encourage you to pseudocode your "gameplan" for any challenge before actually coding. Note that we won't mention writing psuedocode all the time, but it's good practice to implement (especially for new coders) when tackling challenges. Here's an example of how one might pseudocode this challenge (again, don't expect us to do this for you for all challenges!).
-
Write a function
toRomanLazythat takes in a single input,num(an arabic number). Note: this step has already been done for you. -
Create a variable
outputand set it's initial value to the empty string ("") -
Create a variable
romanNumeralToArabicthat holds an object mapping the key of a roman numeral (V) to it's arabic equivalent (5) -
Create a variable
romanNumeralPriorityOrderthat holds an array with the roman numerals in descending order (['M', 'D', 'C' ...]) -
Iterate through
romanNumeralPriorityOrder -
Use division and
Math.floorto find out how many times a givennumcan be divided by the arabic equivalent of the current romanNumeral being iterated through. Append this many of the given romanNumeral to theoutput -
Subtract
numby that number so only the remaining portion that couldn't be divided is left. -
Continue iterating until
num === 0 -
return
output
Given a number in today's numbers, (Arabic Numeral), return its equivalent in Roman Numerals in the lazy way. Lazy Roman Numerals is where Roman Numerals are added together (9 is VIIII, 4 is IIII). Here are Roman Numerals with their Arabic Numeral counterparts:
I -> 1
V -> 5
X -> 10
L -> 50
C -> 100
D -> 500
M -> 1000
toRomanLazy(4); // 'IIII'
toRomanLazy(150); // 'CL'
toRomanLazy(944); // 'DCCCCXXXXIIII'Modify the code in Step 1 to do real roman numeral. Real roman numerals also includes special characters to represent 4, 9, 40, 400, 900 etc:
IV -> 4
IX -> 9
XL -> 40
CD -> 400
CM -> 900
toRoman(4); // 'IV'
toRoman(150); // 'CL'
toRoman(944); // 'CMXLIV'Note: DO NOT concern yourself with very large numbers. Your algorithm should keep appending 'M' for each thousand. (Numbers over 3000 have different numerical representations)