Javascript String rjust(num, padding)

Description

Javascript String rjust(num, padding)

String.prototype.rjust = function(num, padding){
    if(!padding) padding = ' ';
    var s = this.toString();
    if(1 != padding.length) throw new Error('Padding must be one character.');
    if(s.length >= num) return s;
    for(var i=0; i<=num-s.length; i++)
        s = padding + s;/*from  w  w  w .j  a va2  s  .  c  om*/
    return s;
};



PreviousNext

Related