Return the intersection of two arrays given in parameter - Node.js Array

Node.js examples for Array:Set Operation

Description

Return the intersection of two arrays given in parameter

Demo Code


/**/*from w  w  w.j  a v a 2  s .c o m*/
 * Return the intersection of two arrays given in parameter
 *
 * @param arr1
 * @param arr2
 * @return {[]} The intersection of the two arrays.
 */
intersect = function(arr1, arr2) {
  return arr1.filter(function(n) {
    return arr2.indexOf(n) > -1;
  });
};

Related Tutorials