Nodejs Number to Roman Number Convert to_roman()

Here you can find the source of to_roman()

Method Source Code

mapa = {0:"", 1:"I", 5:"V", 10:"X"}
lista = [0, 1, 5, 10]//  w ww  .j ava2s  .  c  om

Number.prototype.to_roman = function() {
    if(this in mapa) return mapa[this]
    var num = menor_que(this, mapa)
    if((this+num) in mapa) return num.to_roman() + (this+num).to_roman()
    
    return num.to_roman() + (this-num).to_roman()
}

function menor_que(num, mapa) {
    for(var i = 0; lista[i] < num; i++);
    return lista[i-1]
}

Related

  1. convertToRoman(number)
    String.prototype.reverse=function(){return this.split("").reverse().join("");}
    function  {
      var romanNumValueArr = [
      {num: "I", value: 1},
      {num: "V", value: 5},
      {num: "X", value: 10},
      {num: "L", value: 50},
      {num: "C", value: 100},
      {num: "D", value: 500},
    ...