Javascript String rjust( width, padding )

Description

Javascript String rjust( width, padding )


String.prototype.rjust = function( width, padding ) {
  padding = padding || " ";
  padding = padding.substr( 0, 1 );/* www .  jav a 2  s. co m*/
  if( this.length < width )
      return padding.repeat( width - this.length ) + this;
    else
      return this.toString();
};

Javascript String rjust( width, padding )

// http://snipplr.com/view/709/stringcenter-rjust-ljust/
String.prototype.rjust = function( width, padding ) {
  padding = padding || " ";
  padding = padding.substr( 0, 1 );/*  ww w .  ja va2  s. c  o  m*/
  if( this.length < width )
    return padding.repeat( width - this.length ) + this;
  else
    return this;
}



PreviousNext

Related