Created
August 10, 2022 17:03
-
-
Save danielstern/bd712faa0873d600edac95e786482c9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} num | |
* @return {string} | |
*/ | |
const map = { | |
1 : "I", | |
5 : "V", | |
10 : "X", | |
50 : "L", | |
100 :"C", | |
500: "D", | |
1000 : "M" | |
} | |
const romanValueMap = { | |
"I" : 1, | |
"V" : 5, | |
"X" : 10, | |
"L" : 50, | |
"C" : 100, | |
"D" : 500, | |
"M": 1000 | |
} | |
var intToRoman = function(num) { | |
const map2 = { | |
}; | |
const ints = Object.keys(map).reverse(); | |
console.log(ints); | |
let n = num; | |
for (const int of ints) { | |
let t = ~~(n / int); | |
let mod = n % int; | |
n = mod; | |
map2[int] = t; | |
} | |
console.log(map2); | |
const symbols = Object.values(map).reverse(); | |
let str = ``; | |
const map3 = { | |
}; | |
for (const symbol of symbols) { | |
const symbolValue = romanValueMap[symbol]; | |
const symbolTimes = map2[symbolValue]; | |
map3[symbol] = symbolTimes; | |
} | |
console.table(map3); | |
for (symbol of symbols) { | |
const count = map3[symbol]; | |
for (i = 0; i < count; i++) { | |
str += symbol; | |
} | |
} | |
return str; | |
// for (let int in map) { | |
// } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment