View intToRoman.js
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
var intToRoman = function (num) { | |
let output = ""; | |
const bases = [1000, 100, 10, 1]; | |
for (let base of bases) { | |
const q = Math.floor(num / base); | |
const rem = num % base | |
if (q > 0) { | |
output += toFullBaseRoman(q, base); | |
} | |
num = rem; |
View romanToInt.js
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
const romanToInt = function (s) { | |
let total = 0; | |
for (let i = 0; i < s.length;) { | |
let currentVal = valueMap[s[i]]; | |
if (i === s.length - 1) { | |
total += currentVal; | |
break; | |
} | |
let nextVal = valueMap[s[i + 1]]; | |
if (currentVal < nextVal) { |
View bumpme
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
Tue Mar 5 09:03:23 UTC 2019 |