From b336cd3caa6565efb4dfbebef5c332185e35e7e9 Mon Sep 17 00:00:00 2001 From: Sajib Date: Thu, 20 Oct 2022 16:11:26 +0600 Subject: [PATCH] 12-Integer-to-Roman.js --- PARTICIPANTS.md | 10 +++++++++ javascript/12-Integer-to-Roman.js | 37 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 javascript/12-Integer-to-Roman.js diff --git a/PARTICIPANTS.md b/PARTICIPANTS.md index 5a2e2f4..2ea2a5b 100644 --- a/PARTICIPANTS.md +++ b/PARTICIPANTS.md @@ -142,3 +142,13 @@ - šŸ”­ Connect with me: **[Piyushjar](https://github.com/piyushjar))** --- +### Connect with me: + + + +- šŸ‘Øā€šŸ’» My name is **Sajib** +- 🌱 I’m a MERN Stack Developer. +- šŸ“« Reach me: **contact2sajib@gmail.com** +- šŸ”­ Connect with me: **[19sajib](https://github.com/19sajib)** + +--- diff --git a/javascript/12-Integer-to-Roman.js b/javascript/12-Integer-to-Roman.js new file mode 100644 index 0000000..3c326f3 --- /dev/null +++ b/javascript/12-Integer-to-Roman.js @@ -0,0 +1,37 @@ +/** + * @param {number} num + * @return {string} + */ + var intToRoman = function(num) { + const romanValue = { + I: 1, + IV: 4, + V: 5, + IX: 9, + X: 10, + XL: 40, + L: 50, + XC: 90, + C: 100, + CD: 400, + D: 500, + CM: 900, + M: 1000, + }; + let result = ''; + + for (key in romanValue) { + const repeatCount = Math.floor(num / romanValue[key]); + + if (repeatCount !== 0) { + result += key.repeat(repeatCount); + } + + num %= romanValue[key]; + + if (num === 0) return result; + } + + return result; + +}; \ No newline at end of file