Javascript Array intersect(b)

Description

Javascript Array intersect(b)


   /*from   w w w .  j  av a 2s. com*/
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;
}



PreviousNext

Related