Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Roman Numerals Clear solution in Clear category for [old] Roman Numerals by Taylor_Page
"use strict";
function romanNumerals(number) {
let result = ""
// Decimal cases needed
const DEC = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
// Roman Numeral equivalancies of cases needed
const ROMAN = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
for (let i = 0; i < DEC.length; i++) {
while (number % DEC[i] < number) {
result += ROMAN[i]
number -= DEC[i]
}
}
return result;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(romanNumerals(6), 'VI', "First");
assert.equal(romanNumerals(76), 'LXXVI', "Second");
assert.equal(romanNumerals(499), 'CDXCIX', "Third");
assert.equal(romanNumerals(3888), 'MMMDCCCLXXXVIII', "Forth");
console.log("Done! Go Check!");
}
March 19, 2019
Comments: