Nodejs Array Intersect intersection(t)

Here you can find the source of intersection(t)

Method Source Code

Array.prototype.intersection = function(t)
{
// s.intersection(t) -->
// new array with elements common to s and t
    var s = this.toHash();
    var t = t.toHash();
    var intersection = [];
    s.keys().forEach(function(item)
    {//  w  w w. j a  va 2 s. c o  m
        if (t.containsKey(item))
            intersection.push(item);
    });
    t.keys().forEach(function(item)
    {
        if (s.containsKey(item))
            intersection.push(item);
    });
    return intersection;
}

Related

  1. 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;
    
  2. 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;
    };
    
  3. intersectintersect(otherArray)
    Array.prototype.intersect = function intersect(otherArray) {
      return this.filter(function(item) {
        return otherArray.has(item);
      });
    };
    
  4. intersection(arr)
    Array.prototype.intersection = function(arr){
      return this.filter(function(n){
        return arr.indexOf(n) != -1;
      });
    
  5. 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;