• API
• FAQ
• Tools
• Archive
daily pastebin goal
92%
SHARE
TWEET

# Untitled

a guest May 16th, 2018 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. <!DOCTYPE html>
2. <html>
4.   <meta charset="utf-8">
5.   <meta name="viewport" content="width=device-width">
6.   <title>Roman Numerals Encoder</title>
8. <body>
9. Create a function taking a positive integer as its parameter and returning a string containing the Roman Numeral representation of that integer.
10. <br/>
11. Modern Roman numerals are written by expressing each digit separately starting with the left most digit and skipping any digit with a value of zero. In Roman numerals 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC. 2008 is written as 2000=MM, 8=VIII; or MMVIII. 1666 uses each Roman symbol in descending order: MDCLXVI.
12. <br/>
13. Example:
14. <br/>
15. solution(1000); // should return 'M'
16. Help:
17. <br/>
18. Symbol    Value
19. I          1<br/>
20. V          5<br/>
21. X          10<br/>
22. L          50<br/>
23. C          100<br/>
24. D          500<br/>
25. M          1,000<br/>
26. Remember that there can't be more than 3 identical symbols in a row.
27. <script id="jsbin-javascript">
28. function solution(number){
29.   if (!+number)
30.         return NaN;
31.     var digits = String(+number).split(""),
32.         key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
33.                "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
34.                "","I","II","III","IV","V","VI","VII","VIII","IX"],
35.         roman = "",
36.         i = 3;
37.     while (i--)
38.         roman = (key[+digits.pop() + (i * 10)] || "") + roman;
39.         console.log( Array(+digits.join("") + 1).join("M") + roman);
40.
41.     return Array(+digits.join("") + 1).join("M") + roman;
42. }
43. </script>
44.
45.
46.
47. <script id="jsbin-source-javascript" type="text/javascript">function solution(number){
48.   if (!+number)
49.         return NaN;
50.     var digits = String(+number).split(""),
51.         key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
52.                "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
53.                "","I","II","III","IV","V","VI","VII","VIII","IX"],
54.         roman = "",
55.         i = 3;
56.     while (i--)
57.         roman = (key[+digits.pop() + (i * 10)] || "") + roman;
58.         console.log( Array(+digits.join("") + 1).join("M") + roman);
59.
60.     return Array(+digits.join("") + 1).join("M") + roman;
61. }
62. </script></body>
63. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.