Skip to content

Instantly share code, notes, and snippets.

@IrakliJani
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save IrakliJani/a6e4c0f67c660169064f to your computer and use it in GitHub Desktop.

Select an option

Save IrakliJani/a6e4c0f67c660169064f to your computer and use it in GitHub Desktop.
// this is unfinished as you can guess...
RomanNumerals = {
dict: {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000,
},
toRoman: function (number) {
var self = this;
return Object.keys(this.dict)
.reverse()
.reduce(function (values, current) {
values.push(Math.floor(number / self.dict[current]));
number %= self.dict[current];
return values;
}, [])
.map(function (e, i) {
return (new Array(e + 1)).join(Object.keys(self.dict).reverse()[i]);
})
.filter(Boolean);
},
fromRoman: function (roman) {
}
}
console.log(RomanNumerals.toRoman(1234));
console.log(RomanNumerals.toRoman(4));
console.log(RomanNumerals.toRoman(1990));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment