Nodejs Array Fill fill(n,v)

Here you can find the source of fill(n,v)

Method Source Code

var n = process.argv[2],
   base = process.argv[3],/*from  ww  w.  j ava 2 s  .co m*/
   decoration = process.argv[4];

Array.prototype.fill = function(n,v) {
    n = n || this.length;
    for( var i = 0; i < n; i++ )  {
        this[i] = v === undefined ? i : v;
   }
    return this;
};

var leftPadding = Math.floor(n / 2);

for (var i = 1; i <= n; i = i + 2, leftPadding = leftPadding - 1) {
   console.log( [].fill(leftPadding, ' ').join('') + [].fill(i, decoration).join('') );
}

console.log( [].fill(Math.floor(n / 2) - 1, ' ').join('') + [].fill(3, base).join('') );

Related

  1. fill( size, m, n )
    function randomNumber (m,n)
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
    Array.prototype.fill = function( size, m, n )
     var i;
    ...
    
  2. fill( val )
    Array.prototype.fill = function( val ) {
      var len = this.length, i;
      if(val instanceof Array){
        for( i = len-1; i >= 0; i--){
          this.push(val);
      } else {
        for( i = 0; i < len; i++){
          this[i] = val;
    ...
    
  3. fill(first, last, value)
    Array.prototype.fill = function (first, last, value) {
        var i;
        for (i = first; i <= last; i++) {
            this[i] = value;
    
  4. fill(n, get)
    Array.prototype.fill = function(n, get)
        for (var i = 0; i < n; i++)
            this[i] = get(i)
        return this
    
  5. fill(value)
    Array.prototype.fill = function (value) {
        var size = this.length;
        while (size > 0) {
            this[--size] = value;
        return this;
    };
    
  6. fill(value)
    Array.prototype.fill = function(value) {
        if (this == null) {
            throw new TypeError('this is null or not defined');
        var O = Object(this);
        var len = O.length >>> 0;
        var start = arguments[1];
        var relativeStart = start >> 0;
        var k = relativeStart < 0 ?
    ...
    
  7. fill(x, y, v, starti, startj)
    Array.prototype.fill = function (x, y, v, starti, startj) {
      if ( ! starti ) {
        starti = 0;
      if ( ! startj ) {
        startj = 0;
      var matrix = this;
      for ( var i = starti; i <= x; i++ ) {
    ...