Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Roman Numerals by Islam_Metov
"use strict";
function romanNumerals(number) {
const ROMAN_NUMERALS = [
["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"],
["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"],
["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"],
["", "M", "MM", "MMM"]
];
return number.toString().split('').reverse().reduce((p, c, i) => ROMAN_NUMERALS[i][Number.parseInt(c)] + p, "");
}
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 6, 2019