Nodejs Array Intersect intersectintersect(otherArray)

Here you can find the source of intersectintersect(otherArray)

Method Source Code

/**// ww w  . j  av  a2s  .  co  m
 * Compare this array with another one and return an array with all the items
 * that are in both arrays.
 * 
 * @param {Array} otherArray The array to compare to
 * @return {Array} An array with all items in this array and otherArray
 */
Array.prototype.intersect = function intersect(otherArray) {
   return this.filter(function(item) {
      return otherArray.has(item);
   });
};

Related

  1. intersect(array)
    Array.prototype.intersect = function(array){
      if(this.length>array.length) return '';
      var equals = true,
          concat = '';
      for(var i = 0; i < this.length-1; i++){
        if(this[i+1] != array[i]){
          equals = false;
          break;
      if(equals){
        concat = this.reduce((acc,k,i) => acc + (i<this.length?k:''), '');
        concat = array.reduce((acc,k,i) => acc + (i>=this.length-1?k:''), concat);
        return concat;
      return '';
    
  2. intersect(ary)
    Array.prototype.intersect = function (ary) {
        return this.union(ary).filter(x => this.contains(x) && ary.contains(x));
    };
    
  3. intersect(b)
    Array.prototype.intersect = function(b) {
      var array = new Array();
      var ua = this.uniquelize();
      var length = ua.length;
      for (var i = 0; i < length; i++) {
        if (b.inArray(ua[i])) {
          array.push(ua[i]);
      return array;
    };
    
  4. intersect(b)
    Array.prototype.intersect = function(b) {
        var flip = {}, res = [];
        for (var i = 0; i < b.length; i++) flip[b[i]] = i;
        for (i = 0; i < this.length; i++)
            if (flip[this[i]] != undefined) res.push(this[i]);
        return res;
    
  5. intersect(tab)
    Array.prototype.intersect = function(tab){
        var temp = [];
        for(var i = 0; i < this.length; i++){
            for(var k = 0; k < tab.length; k++){
                if(this[i] == tab[k]){
                    temp.push( this[i]);
                    break;
        return temp;
    };
    
  6. intersection(arr)
    Array.prototype.intersection = function(arr){
      return this.filter(function(n){
        return arr.indexOf(n) != -1;
      });
    
  7. intersection(arr)
    Array.prototype.intersection = function(arr) {
        var intersection = new Array();
        for (var i = 0; i < arr.length; ++i)
            if (this.contains(arr[i]))
                intersection.push(arr[i]);
        return intersection;
    
  8. intersection(t)
    Array.prototype.intersection = function(t)
        var s = this.toHash();
        var t = t.toHash();
        var intersection = [];
        s.keys().forEach(function(item)
            if (t.containsKey(item))
                intersection.push(item);
    ...