Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Reverse Roman Numerals by vincent.tscherter
"use strict";
function reverseRoman(roman) {
return eval('0'+roman.
replace('IV', '+4').
replace('IX', '+9').
replace('XL', '+40').
replace('XC', '+90').
replace('CD', '+400').
replace('CM', '+900').
replace(/I/g, '+1').
replace(/V/g, '+5').
replace(/X/g, '+10').
replace(/L/g, '+50').
replace(/C/g, '+100').
replace(/D/g, '+500').
replace(/M/g, '+1000'))
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(reverseRoman('VI'), 6, "First")
assert.equal(reverseRoman('LXXVI'), 76, "Second")
assert.equal(reverseRoman('CDXCIX'), 499, "Third")
assert.equal(reverseRoman('MMMDCCCLXXXVIII'), 3888, "Forth")
console.log("Coding complete, Cesar? Click 'Check' to review your tests and earn cool rewards!");
}
Aug. 12, 2017
Comments: