Number to Roman Numeral var romanArray = [];
var toRoman = {

    analyze: function(number){
        romanArray = [];
        if (number &gt;= 1000) {
            return this.thousands(number);
        }else if (number &gt;= 100){
            return this.hundreds(number);
        }else if (number &gt;= 10) {
            return this.tens(number);
        }else{
            return this.last_number(number);
        }
    },

    thousands: function(number){
        var remainder = number % 1000;
        var thousands = Math.floor(number / 1000);
        for(var e = 0; e &lt; thousands; e++) {
            romanArray.push('M');
        }
        return this.hundreds(remainder);
    },

    hundreds: function(number){
        var remainder = number % 100;
        var hundreds = Math.floor(number / 100);
        if (hundreds === 4){
            romanArray.push('CD');
        }else if(hundreds === 9){
            romanArray.push('CM');
        }else if(hundreds &gt;= 5 &amp;&amp; hundreds &lt; 9){
            romanArray.push('D');
            for(var i = 0; i &lt; (hundreds % 5); i++) {
                romanArray.push('C');
            }
        }else if (hundreds &gt; 0 &amp;&amp; hundreds &lt; 4){
            for(var e = 0; e &lt; hundreds; e++) {
                romanArray.push('C');
            }
        }else{

        }
        return this.tens(remainder);
    },

    tens: function(number){
        var remainder = number % 10;
        var tens = Math.floor(number / 10);
        if (tens === 4){
            romanArray.push('XL');
        }else if(tens === 9){
            romanArray.push('XC');
        }else if(tens &gt;= 5 &amp;&amp; tens &lt; 9){
            romanArray.push('L');
            for(var i = 0; i &lt; (tens % 5); i++) {
                romanArray.push('X');
            }
        }else if (tens &gt; 0 &amp;&amp; tens &lt; 4){
            for(var e = 0; e &lt; tens; e++) {
                romanArray.push('X');
            }
        }else{

        }
        return this.last_number(remainder);
    },

    last_number: function (number){
        if (number === 4){
            romanArray.push('IV');
        }else if(number === 9){
            romanArray.push('IX');
        }else if(number &gt;= 5 &amp;&amp; number &lt; 9){
            romanArray.push('V');
            var remainder = number % 5;
            for(var i = 0; i &lt; remainder; i++) {
                romanArray.push('I');
            }
        }else if (number &gt; 0 &amp;&amp; number &lt; 4){
            for(var e = 0; e &lt; number; e++) {
                romanArray.push('I');
            }
        }else{

        }
        return romanArray.join('');
    }
};

console.log(toRoman.analyze(1000));
console.log(toRoman.analyze(2999));
console.log(toRoman.analyze(2555));


I'm wondering if this JavaScript can be refactored using some sort of base/template function.
For Example:

base_function: function (number, four, nine, five, one){
    if (number === 4){
        romanArray.push(four);
    }else if(number === 9){
        romanArray.push(nine);
    }else if(number &gt;= 5 &amp;&amp; number &lt; 9){
        romanArray.push(five);
        var remainder = number % 5;
        for(var i = 0; i &lt; remainder; i++) {
            romanArray.push(one);
        }
    }else if (number &gt; 0 &amp;&amp; number &lt; 4){
        for(var e = 0; e &lt; number; e++) {
            romanArray.push(one);
        }
    }else{

    }
    return romanArray;
},


How can I improve this code?
You may be aware that there are simpler answers to this problem, such as:

function toRoman(n) {
    var r = '',
        decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
        roman = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
    for (var i = 0; i &lt; decimals.length; i++) {
        while (n &gt;= decimals[i]) {
            r += roman[i];
            n -= decimals[i];
        }
    }
    return r;
}


Bearing this in mind it might be useful to explain what exactly you are trying to achieve with your refactoring? E.g. is it to practice using more complicated language patterns?