Javascript Array minus(secondarr)

Description

Javascript Array minus(secondarr)


Array.prototype.minus = function(secondarr){
  // subtracts the secondarr from this,
  // works best with arrays of strings
  var result = this;
  for (var i = result.length - 1; i >= 0; i--) {
    for (var j = secondarr.length - 1; j >= 0; j--) {
      if (secondarr[j].match(result[i])){
        result = result.without(i);/*from   w  w w .j av a 2  s.  c om*/
        break;
      };
    };
  };
  return result;
};

Javascript Array minus(secondarr)

Array.prototype.minus = function(secondarr){
  // subtracts the secondarr from this,
  // works best with arrays of strings
  var result = this;
  for (var i = result.length - 1; i >= 0; i--) {
    for (var j = secondarr.length - 1; j >= 0; j--) {
      if (secondarr[j].match(result[i])){
        result = result.without(i);//from w  ww  .java2s .co  m
        break;
      }
    }
  }
  return result;
};



PreviousNext

Related