Skip to content

Instantly share code, notes, and snippets.

View intToRoman.js
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
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) {
@uttamk
uttamk / bumpme
Last active Mar 5, 2019
Test gist
View bumpme
Tue Mar 5 09:03:23 UTC 2019