File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
25
25
removeEmptyLinesFromString ,
26
26
removeNewLinesAndExtraSpaces ,
27
27
toFixedLocale ,
28
+ convertArabicToRoman
28
29
} from "./str" ;
29
30
import { containsEncodedComponents } from "./url" ;
30
31
import { getUUID } from "./uuid" ;
@@ -59,4 +60,5 @@ export {
59
60
getUUID ,
60
61
getSearchQuerySelector ,
61
62
containsEncodedComponents ,
63
+ convertArabicToRoman ,
62
64
} ;
Original file line number Diff line number Diff line change @@ -54,3 +54,35 @@ export function removeEmptyLinesFromString(string) {
54
54
// remove "\n" on empty lines AND the very last "\n"
55
55
return string . replace ( / ^ \s * [ \r \n ] / gm, "" ) . trim ( ) ;
56
56
}
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
+ }
You can’t perform that action at this time.
0 commit comments