Nodejs Array Minus minus(arr)

Here you can find the source of minus(arr)

Method Source Code

Array.prototype.minus = function (arr) {
    var result = new Array();
    var obj = {};
    for (var i = 0; i < arr.length; i++) {
        obj[arr[i]] = 1;//from w w w. j a  v a2 s  . com
    }
    for (var j = 0; j < this.length; j++) {
        if (!obj[this[j]])
        {
            obj[this[j]] = 1;
            result.push(this[j]);
        }
    }
    return result;
};

Related

  1. minus(a)
    Array.prototype.minus = function(a) {
        return this.filter(function(i) { return a.indexOf(i) < 0; });
    };
    
  2. minus(a, b)
    Array.minus = function(a, b){
         return a.uniquelize().each(function(o){return b.contains(o) ? null : o});
    };
    
  3. 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;
    };
    
  4. 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;
    };
    
  5. minus(other)
    Array.prototype.minus = function(other) {
        if (typeof(other) == "undefined") {
            return this;
        return this.where(function(e) {
            return !other.contains(e);
        });
    };
    
  6. minus(other, test)
    Array.prototype.minus = function(other, test) {
        return this.filter(function(el){
            return !other.contains(el, test);
        });
    };