File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
2525 removeEmptyLinesFromString ,
2626 removeNewLinesAndExtraSpaces ,
2727 toFixedLocale ,
28+ convertArabicToRoman
2829} from "./str" ;
2930import { containsEncodedComponents } from "./url" ;
3031import { getUUID } from "./uuid" ;
@@ -59,4 +60,5 @@ export {
5960 getUUID ,
6061 getSearchQuerySelector ,
6162 containsEncodedComponents ,
63+ convertArabicToRoman ,
6264} ;
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments