Nodejs Array Value pad(minSize, val)

Here you can find the source of pad(minSize, val)

Method Source Code

Array.prototype.pad = function(minSize, val) {
    var padded = new Array();
    for (var i = 0; i < this.length; i++) {
        padded.push(this[i]);// w  w w.j  a  v  a 2  s  .  co m
    }
    while (padded.length < minSize) {
        padded.push(val || null);
    }
    return padded;
}

Related

  1. hasWhere(property, value)
    Array.prototype.hasWhere = function (property, value) {
        "use strict";
        for(var i = 0; i < this.length; i++) {
            if(this[i][property] === value) {
                return true;
        return false;
    };
    ...
    
  2. iReduce(handler, initialValue)
    var ary = [0,1,2,3,4,5,6,7,8,9];
    var initialValue;
    Array.prototype.iReduce = function(handler, initialValue) {
      if (typeof handler !== 'function') {
        throw new Error(handler + 'is not a function!');
      var ary = this;
      var i = 0;
      var tempCurrent = initialValue;
    ...
    
  3. makeArray(value){
    Array.makeArray = function(value){
      if ( !value ) return [];
      if ( typeof value == "string" ) return [value];
      return Array.prototype.slice.call(value, 0);
    };
    
  4. nIndexOf(value)
    Array.prototype.nIndexOf = function(value){
        var firstIndex = 0,
            lastIndex = this.length - 1,
            middleIndex = Math.floor((lastIndex + firstIndex) / 2);
        while (this[middleIndex] != value && firstIndex < lastIndex) {
            if (value < this[middleIndex]) {
                lastIndex = middleIndex - 1;
            } else if (value > this[middleIndex]) {
                firstIndex = middleIndex + 1;
    ...
    
  5. oneValue()
    Array.prototype.oneValue = function()
        var max = this[0];
        for(el in this)
            if(this[el] !== max && !isNaN(this[el]))
                return false;
        return true;
    };
    
  6. plumRemove(elemVal)
    Array.prototype.plumRemove = function(elemVal){
      var i = this.indexOf(elemVal);
      if(i>-1){
        this.splice(i, 1);
    };
    
  7. query(field, operator, value)
    Array.prototype.query = function (field, operator, value) { 
        if (operator=="contains"){
            value = value.toLowerCase();
          return this.filter(function (item){
           return item[field].toLowerCase().indexOf(value) !== -1;   
        });
      else if(operator == "==") {
        return this.filter(function (item){
    ...
    
  8. resize(newSize, defaultValue = 0)
    Array.prototype.resize = Array.prototype.resize || function(newSize, defaultValue = 0) {
        while (newSize > this.length) {
            this.push(defaultValue);
        this.length = newSize;
    };
    
  9. resizeMatrix(rowsSize, columnsSize, defaultValue = 0)
    Array.prototype.resizeMatrix = Array.prototype.resizeMatrix || function(rowsSize, columnsSize, defaultValue = 0) {
        while (rowsSize > this.length) {
            var row = [];
            row.resize(columnsSize, defaultValue);
            this.push(row);
        this.length = rowsSize;
    };