Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.



Excerpt
hiddentrue

excluded(arrayA, arrayB) Returns an Array of all items in one Array that are not contained within another Array.


Function: excluded()

Returns an Array of all items in one Array that are not contained within another Array.

Syntax

excluded(setAarrayA, setBarrayB)

ArgumentTypeDescription
setA
arrayAArrayAn Array of values of any type.
setB
arrayBArrayAn Array of values of any type.

Returns an Array of all items that are in setA arrayA that are not in setB arrayB.

Examples

excluded(["a","b","c","d","e"],["a", "c","f","d"])

Returns the Array ["b","e"], as do the three expressions below:

listToString(excluded(["a","b","c","d","e"],["a", "c","f","d"]))
listToString(excluded(["a","a","b","c","d","e"],["a", "c","f","d"]))
listToString(excluded(["a","b","c","d","e"],["a","a","c","f","d"]))


If an excluded element appears more than once in the first array (array A), then it will appear the same number of times in the array returned:

excluded(["a","b","c","d","e","e"],["a", "c","f","d"])

returns

["b","e","e"].

To be clear, if an element in the first array (array A) exists at all in the comparator array (array B), then it will not count as excluded:

excluded(["a","b","c","d","e","e"],["a", "c","f","d","e"])

returnsĀ 

["b"]


Note that if you want to construct conditional expression using excluded() as a predicate, you should use an intermediary countElements() function:

Code Block
//a list of managers known to us
$validManagersList = ["Rob","Bob"],

//a list that will only have a member if the manager on the output record
//is not found in the list of known managers 
$exclusions = excluded(_out.Manager, $validManagersList),

if(countElements($exclusions) > 0, addElement($errorArray, "The manager on this record was not found in the list of known managers")),

This will add to a list of errors if there is (at least) one member in the list of exclusions.

See Also