You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// get the value of digit in the thousandth postion (e.g. 3576 => 3) and accesses at index of the value of the digit (e.g. 3576 => thousands[3] = 'MMM')
__The challenge:__ <p>Convert a regular number to a Roman Numeral</p>
718
718
719
719
720
-
__Algorithmic Thinking:__ <p> </p>
720
+
__Algorithmic Thinking:__ <p>You want to convert a number to a roman numeral... the trick to this problem is to kind of "split" the problem to individual digits. Instead of doing some weird convoluted solution, you should see that each digit would map to a string value and they only "add up".
721
721
722
+
**Example**
723
+
- DXXXII = 532
724
+
- Now, let's think about this example step by step. Let's take 500 out of 532. What is 500 in roman numeral? `500=D`, right? We "append" that to our "string". now we evaluate 32... so 32 is essentially 30 + 2, so we take out 30 this time. `30=XXX`, then append to "string". And finally, we have 2... you can't really "destructure" 2 any further so we have `2=II`, and then append to string...
725
+
- now we have `"D"+"XXX"+"II"=532`, YAY!!!
726
+
</p>
722
727
723
-
__code Implementation:__ <p> </p>
728
+
729
+
__code Implementation:__ <p>
730
+
731
+
```javascript
732
+
// A regular number
733
+
constnum=3;
734
+
735
+
// convert a number from 0 - 3000 to a roman numeral
// get the value of digit in the thousandth postion (e.g. 3576 => 3) and accesses at index of the value of the digit (e.g. 3576 => thousands[3] = 'MMM')
0 commit comments