Nodejs Array Intersect intersect

Here you can find the source of intersect

Method Source Code

/**/* www .j av  a  2  s . co  m*/
 * Compare this array with another one and return an array with all the items
 * that are in both arrays.
 * @jsver 1.8+
 * 
 * @param {Array} otherArray The array to compare to
 * @return {Array} An array with all items in this array and otherArray
 */
Array.prototype.intersect =
   function(otherArray) [ i for each( i in this ) if( otherArray.has( i ) ) ];

Related

  1. intersect(a)
    Array.prototype.intersect = function(a) {
        return this.filter(function(x) {
      return a.indexOf(x) >= 0;
        });
    
  2. intersect(a, b)
    Array.intersect = function(a, b){
         return a.uniquelize().each(function(o){return b.contains(o) ? o : null});
    };
    
  3. intersect(ar)
    Array.prototype.intersect = function(ar) {
      var results = [];
      for (var i = 0, len = this.length; i < len; i++) {
        for (var j = 0, len2 = ar.length; j < len2; j++) {
          if (this[i] === ar[j]) {
            var found = false;
            for (var k = 0, len3 = results.length; k < len3; k++) {
              if (ar[j] === results[k]) {
                found = true;
    ...
    
  4. intersect(arr)
    Array.prototype.intersect = function (arr) {
      return this.filter(function (el, idx) {
        return arr.indexOf(el) >= 0;
      }).unique();
    };