Skip to content

Commit e30d12b

Browse files
Merge pull request #28 from Exabyte-io/feature/SOF-6316
feat: added convert from arabic to roman helper function
2 parents fbf8f72 + 1cc674d commit e30d12b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/utils/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
removeEmptyLinesFromString,
2626
removeNewLinesAndExtraSpaces,
2727
toFixedLocale,
28+
convertArabicToRoman
2829
} from "./str";
2930
import { containsEncodedComponents } from "./url";
3031
import { getUUID } from "./uuid";
@@ -59,4 +60,5 @@ export {
5960
getUUID,
6061
getSearchQuerySelector,
6162
containsEncodedComponents,
63+
convertArabicToRoman,
6264
};

src/utils/str.js

+32
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,35 @@ export function removeEmptyLinesFromString(string) {
5454
// remove "\n" on empty lines AND the very last "\n"
5555
return string.replace(/^\s*[\r\n]/gm, "").trim();
5656
}
57+
58+
/**
59+
* converts simple number to roman.
60+
* @param {Number} num
61+
* @returns {String} - string
62+
*/
63+
export function convertArabicToRoman(num) {
64+
var roman = {
65+
M: 1000,
66+
CM: 900,
67+
D: 500,
68+
CD: 400,
69+
C: 100,
70+
XC: 90,
71+
L: 50,
72+
XL: 40,
73+
X: 10,
74+
IX: 9,
75+
V: 5,
76+
IV: 4,
77+
I: 1
78+
};
79+
let str = '';
80+
81+
for (const i of Object.keys(roman)) {
82+
const q = Math.floor(num / roman[i]);
83+
num -= q * roman[i];
84+
str += i.repeat(q);
85+
}
86+
87+
return str;
88+
}

0 commit comments

Comments
 (0)