Nodejs Array Minus minus(secondarr)

Here you can find the source of minus(secondarr)

Method Source Code

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);//  www  .j a  va2s .  c om
        break;
      };
    };
  };
  return result;
};

Related

  1. minus(arr)
    Array.prototype.minus = function (arr) {
        var result = new Array();
        var obj = {};
        for (var i = 0; i < arr.length; i++) {
            obj[arr[i]] = 1;
        for (var j = 0; j < this.length; j++) {
            if (!obj[this[j]])
                obj[this[j]] = 1;
                result.push(this[j]);
        return result;
    };
    
  2. minus(b)
    Array.prototype.minus = function(b) {
      var array = new Array();
      var ua = this.uniquelize();
      var length = this.length;
      for (var i = 0; i < length; i++) {
        if (!b.inArray(ua[i])) {
          array.push(ua[i]);
      return array;
    };
    
  3. minus(list)
    Array.prototype.minus = function (list) {
        var result = [];
        for (var i = 0; i < this.length; i++) {
            if (list.indexOf(this[i]) < 0)
                result.push(this[i]);
        return result;
    };
    
  4. minus(other)
    Array.prototype.minus = function(other) {
        if (typeof(other) == "undefined") {
            return this;
        return this.where(function(e) {
            return !other.contains(e);
        });
    };
    
  5. minus(other, test)
    Array.prototype.minus = function(other, test) {
        return this.filter(function(el){
            return !other.contains(el, test);
        });
    };
    
  6. minusAsString(list)
    Array.prototype.minusAsString = function (list) {
        var result = [];
        for (var i = 0; i < this.length; i++) {
            var notIn = true;
            for (var j = 0; j < list.length; j++) {
                if (list[j].toString() == this[i].toString()) {
                    notIn = false;
                    break;
            if (notIn)
                result.push(this[i]);
        return result;
    };
    
  7. minusIndex(idx)
    Array.prototype.minusIndex = function(idx) {
        if(idx < 0 || idx >= this.length) return this;
        return this.slice(0, idx).concat(this.slice(idx + 1));