function convert(num) {
 //return num;
  var nums = [1000,900,500,400,100,90,50,40,10,9,5,4,1];
  var romans = ['m','cm','d','cd','c','xc','l','xl','x','ix','v','iv','i'];
  var str = '';
  nums.forEach(function(item,index,array){
    while (num >= item){
      str += romans[index];
      num -= item;
    }
  });
  return str.toUpperCase();
}

convert(36);

 

posted on 2016-12-16 14:02  梦如影  阅读(95)  评论(0编辑  收藏  举报