Array intersection

Given two arrays (or “collections”), what elements are found in both?

[{"$type":"CommentBlock","parts":{"comment":{"value":"the following test data should return the array [3,4,5]"},"next":{"$type":"CommentBlock","parts":{"comment":{"value":"{\n   \"Array1\": [1,2,3,3,3,4,5],\n   \"Array2\": [3,3,3,4,5,6,7]\n}"},"next":{"$type":"DeclareVariableBlock","parts":{"itemVar":{"value":"returnArray"},"type":{"value":"any[]"},"next":{"$type":"ForEachBlock","parts":{"itemVar":{"value":"thisArray1Element"},"arrayVar":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"Array1"}}},"statement":{"$type":"IfBlock","parts":{"v":2,"if":{"$type":"FindBlock","parts":{"mode":{"value":"some"},"itemVar":{"value":"item"},"array":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"Array2"}}},"predicate":{"$type":"CompareBlock","parts":{"left":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"item"}}},"operator":{"value":"=="},"right":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"thisArray1Element"}}}}}}},"then":{"$type":"IfBlock","parts":{"v":2,"if":{"$type":"NotBlock","parts":{"value":{"$type":"Contains","parts":{"Array":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"returnArray"}}},"Item":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"thisArray1Element"}}}}}}},"then":{"$type":"AddToArrayBlock","parts":{"Item":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"thisArray1Element"}}},"Array":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"returnArray"}}}}}}}}},"next":{"$type":"ReturnBlock","parts":{"value":{"$type":"GetVariableBlock","parts":{"variable1":{"value":"returnArray"}}}}}}}}}}}}}]

(triple-click to select this code. Then copy, open a snap workspace, and right-click in the workspace to “paste JSON” it into your KBMax instance.)

Was this article helpful?