JSFiddle - React, Tailwind, and code Playground

by Julian

HTML

<div id="results"></div>

JavaScript

// Prototype extension:
//   Array#translate maps an array through a hash or a map.
//   Also extends Array#map to accept a hash/map as iterator.


Object.extend(Array.prototype, {
    translate: function(translationsHash) {
        return this.map(function(entry) {
            return Object.isHash(translationsHash) ? translationsHash.get(entry) : translationsHash[entry];
        });
    },
    map: Array.prototype.map.wrap(function(proceed, iterator, index, context) {
        if (Object.isFunction(iterator)) {
            return proceed(iterator, index, context);
        } else {
            return this.translate(iterator);
        }
    })
});

var RomanNumeralValues = {
    M: 1000,
    D: 500,
    C: 100,
    L: 50,
    X: 10,
    V: 5,
    I: 1
};
var result = Object.keys(RomanNumeralValues).map(RomanNumeralValues);
$("results").update(result);