/**
 * @Roman Numbers Converter
 * @author Hatem A. <hatem@tuta.io>
 * @version 1.0
 * @licence Licensed under the Apache License, Version 2.0
 */

// basic roman symbols
var symbols =[{1:"I",5:"V",10:"X",50:"L",100:"C",500:"D",1000:"M"}];

/**
   * Breaks number into decimal places.
   *
   * @param {Integer} num - the number .
   * @returns {Array} decimal places.
   */
function numberBreaker(num){

  var str = num.toString();
  var len = str.length;
  var brokenNums = [];
  var mult = 1;
  
  for(var i = (len - 1); i >= 0 ;i--){
    var decNum = parseInt(str[i]) * mult;
    if(decNum !== 0){
      brokenNums.push(decNum);
    }
    
    mult = mult * 10;
  }
  
  brokenNums.reverse();
  return brokenNums;  
}

/**
   * Convert number into roman number.
   *
   * @param {Integer} num - the number .
   * @returns {String} number in roman pattern.
   */
function convertToRoman(num){
  var romanNumber = getSymbol(num);
  
  if(romanNumber == undefined){
    
    romanNumber = "";
    var brokenNums = numberBreaker(num);

    for(var i=0;i < brokenNums.length;i++){
      var romanDecNum = convertDecimalNumberToRoman(brokenNums[i]);
      romanNumber += romanDecNum;
    }
  }
  
  return romanNumber;
}

/**
   * Convert decimal number into roman number.
   *
   * @param {Integer} num - the number .
   * @returns {String} number in roman pattern.
   */
function convertDecimalNumberToRoman(num){
  var symbol =  getSymbol(num);
  if(symbol !== undefined){
    return symbol;
  }else if(num < 1000) {
    var symbolsByKey = Object.keys(symbols[0]);
    for (var i= 0; i < symbolsByKey.length; i++){
      var current = symbolsByKey[i];
      var next = symbolsByKey[i+1];

      if(num > current && num < next){
        return calculateSymbol(num,current,next);        
      }
    }
  }else if(num > 1000){
    return calculateSymbol(num,null,null); 
  }
}

/**
   * Calculate the roman symbol.
   *
   * @param {Integer} num - the number .
   * @param {Integer} low - the left roman basic number.
   * @param {Integer} high - he right roman basic number.
   * @returns {String} number in roman pattern.
   */
function calculateSymbol(num,low,high){
  var mult = getDecimalPlace(num);
  var symbol = "";
  if(num < 1000){
   if(num == (high-mult)){
      symbol = getSymbol(mult) + getSymbol(high);
      return symbol;
    }else{
      var diff = (num - low);
      var div = diff/mult;
      var total = 0;

      for(var i=1;i<=div;i++){
          total += mult;
          symbol += symbols[0][mult];
      }

      if(num - low - total > 0){
         symbol += convertDecimalNumberToRoman(num - low - total);
      }

      symbol = symbols[0][low] + symbol;
      return symbol;
    }   
  }else{

    var numAfterThousands = num;
    while(numAfterThousands > 1000){
      numAfterThousands -= 1000;
      symbol += getSymbol(1000);
      
      symbol += convertDecimalNumberToRoman(numAfterThousands);
      return symbol;
    }
  }
  
}


/**
   * Get roman basic number symbol..
   *
   * @param {Integer} num - the number .
   * @returns {String} number in roman pattern.
   */
function getSymbol(num){
  return symbols[0][num];
}


/**
   * Get decimal place multiple.
   *
   * @param {Integer} num - the number .
   * @returns {Integer} multiple.
   */
function getDecimalPlace(num){
  var mult = 10;
  
    if(num < 10){
      mult = 1;
    }else{
       while(num/mult > 10){
         mult *= 10;
       }
    }
  
  return mult;
}


@@ -238,489 +238,8 @@
 %5D;%0A%0A
-/**%0A   * Breaks number into decimal places.%0A   *%0A   * @param %7BInteger%7D num - the number .%0A   * @returns %7BArray%7D decimal places.%0A   */%0Afunction numberBreaker(num)%7B%0A%0A  var str = num.toString();%0A  var len = str.length;%0A  var brokenNums = %5B%5D;%0A  var mult = 1;%0A  %0A  for(var i = (len - 1); i %3E= 0 ;i--)%7B%0A    var decNum = parseInt(str%5Bi%5D) * mult;%0A    if(decNum !== 0)%7B%0A      brokenNums.push(decNum);%0A    %7D%0A    %0A    mult = mult * 10;%0A  %7D%0A  %0A  brokenNums.reverse();%0A  return brokenNums;  %0A%7D%0A
 %0A/**
@@ -728,24 +728,507 @@
 nNumber;%0A%7D%0A%0A
+/**%0A   * Breaks number into decimal places.%0A   *%0A   * @param %7BInteger%7D num - the number .%0A   * @returns %7BArray%7D decimal places.%0A   */%0Afunction numberBreaker(num)%7B%0A%0A  var str = num.toString();%0A  var len = str.length;%0A  var brokenNums = %5B%5D;%0A  var mult = 1;%0A  %0A  for(var i = (len - 1); i %3E= 0 ;i--)%7B%0A    var decNum = parseInt(str%5Bi%5D) * mult;%0A    if(decNum !== 0)%7B%0A      brokenNums.push(decNum);%0A    %7D%0A    %0A    mult = mult * 10;%0A  %7D%0A  %0A  brokenNums.reverse();%0A  return brokenNums;  %0A%7D%0A%0A%0A
 /**%0A   * Con

Change place of main function to top