ArrayIntersection (open)
Returns an array containing all elements present in both arrays
Syntax
LOADLIB "wh::util/algorithms.whlib";
VARIANT FUNCTION ArrayIntersection(VARIANT first, VARIANT second)
Parameters
VARIANT first
The first array to use in the comparison
VARIANT second
The second array to use in the comparison
Return value
VARIANT
An array containing all the entries that are present in both arrays.
Description
Searches for values in the second array that are also present in the first array and returns the an array containing all matches found. When no matches are found, an empty array of the type given is returned. Arrays must be of the same type.
Examples
STRING ARRAY alpha := [ "foo", "bar", "baz", "test", "alpha", "beta", "charlie" ];
STRING ARRAY bravo := [ "delta", "echo", "foxtrot", "baz", "bar", "golf", "hotel" ];
STRING ARRAY charlie := [ "foo1", "bar1", "baz1", "test1", "alpha1", "beta1", "charlie1" ];
STRING ARRAY delta := [ "foo", "bar", "baz", "test", "alpha", "beta", "charlie" ];
// returns ["bar", "baz"]
STRING ARRAY matches1 := ArrayIntersection(alpha, bravo);
// returns DEFAULT STRING ARRAY
STRING ARRAY matches2 := ArrayIntersection(alpha, charlie);
// returns ["foo", "bar", "baz", "test", "alpha", "beta", "charlie"]
STRING ARRAY matches3 := ArrayIntersection(alpha, delta);