Nodejs String Justify ljust( length, char )

Here you can find the source of ljust( length, char )

Method Source Code

String.prototype.ljust = function( length, char ) {
    var fill = [];
    while ( fill.length + this.length < length ) {
        [fill.length] = char;//from  www.java2 s  .  c om
    }
    return this + fill.join('');
}

Related

  1. ljust( width, padding )
    String.prototype.ljust = function( width, padding ) {
      padding = padding || " ";
      padding = padding.substr( 0, 1 );
      if( this.length < width )
        return this + padding.repeat( width - this.length );
      else
        return this.toString();
    
  2. rjust( length, char )
    String.prototype.rjust = function( length, char ) {
        var fill = [];
        while ( fill.length + this.length < length ) {
            fill[fill.length] = char;
        return fill.join('') + this;
    
  3. rjust( width, padding )
    String.prototype.rjust = function( width, padding ) {
      padding = padding || " ";
      padding = padding.substr( 0, 1 );
      if( this.length < width )
          return padding.repeat( width - this.length ) + this;
        else
          return this.toString();
    };
    
  4. rjust( width, padding )
    String.prototype.rjust = function( width, padding ) {
      padding = padding || " ";
      padding = padding.substr( 0, 1 );
      if( this.length < width )
        return padding.repeat( width - this.length ) + this;
      else
        return this;