Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
match & reduce solution in Creative category for [old] Reverse Roman Numerals by Sim0000
"use strict";
const dic = {'I':1, 'IV':4, 'V':5, 'IX':9, 'X':10, 'XL':40, 'L':50, 'XC':90, 'C':100, 'CD':400, 'D':500, 'CM':900, 'M':1000};
function reverseRoman(roman) {
return roman.match(/CD|CM|XL|XC|IV|IX|M|D|C|L|X|V|I/g).reduce((p,c)=>p+dic[c], 0);
}
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!");
}
July 10, 2017