Nodejs Array Value resize(newSize, defaultValue = 0)

Here you can find the source of resize(newSize, defaultValue = 0)

Method Source Code

Array.prototype.resize = Array.prototype.resize || function(newSize, defaultValue = 0) {
    while (newSize > this.length) {
        this.push(defaultValue);/* w w w.  ja v a2  s . co  m*/
    }
    this.length = newSize;
};

Related

  1. 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;
    ...
    
  2. oneValue()
    Array.prototype.oneValue = function()
        var max = this[0];
        for(el in this)
            if(this[el] !== max && !isNaN(this[el]))
                return false;
        return true;
    };
    
  3. pad(minSize, val)
    Array.prototype.pad = function(minSize, val) {
        var padded = new Array();
        for (var i = 0; i < this.length; i++) {
            padded.push(this[i]);
        while (padded.length < minSize) {
            padded.push(val || null);
        return padded;
    ...
    
  4. plumRemove(elemVal)
    Array.prototype.plumRemove = function(elemVal){
      var i = this.indexOf(elemVal);
      if(i>-1){
        this.splice(i, 1);
    };
    
  5. 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){
    ...
    
  6. 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;
    };
    
  7. superJoin(value)
    isNullOrEmpty=function(obj) {
        if (obj == undefined || obj == null || obj == "") {
            return true;
        else {
            return false;
    Array.prototype.superJoin=function(value){
    ...
    
  8. toggleValue(value)
    Array.prototype.toggleValue = function (value) {
        var index = this.indexOf(value);
        if (index === -1) {
            this.push(value);
        else {
            this.splice(index, 1);
    };
    ...
    
  9. trim(value)
    Array.prototype.trim = function (value) {
      var array = this.slice(0); 
      while (array.length > 0 && array[0] === value) {
        array.shift();
      while (array.length > 0 && array[array.length - 1] === value) {
        array.pop();
      return array;
    ...