intersectArr(arr1: Number, arr2: Number);
arr1. Initial array.
arr2. Array that intersects the source array.
The intersectArr method determines intersecting elements for two arrays.
This method returns an Array value.
To execute the example, add a link to PP.js scenario file to HTML page. Create two arrays of integers and find their intersecting elements:
// Determine arrays of integer numbers
var num1 = [5, 1, 9, 6];
var num2 = [2, 9, 6, 7, 5];
// Determine elements of arrays intersection
var arr = PP.intersectArr(num1, num2);
if (arr.length > 0) {
console.log("Elements of intersection of arrays [" + num1 + "] and [" + num2 + "]: [" + arr + "].");
} else {
console.log("Arrays [" + num1 + "] and [" + num2 + "] do not intersect.");
};
After executing the example the browser console displays intersecting elements for two specified arrays:
Intersecting elements of the arrays [5,1,9,6] and [2,9,6,7,5]: [5,9,6].
See also: