How to find out the common and uncommon elements between two arrays. Uncommon Elements DataWeave Logic //How to filter out the uncommon elements between two arrays.
%dw 2.0
output application/json
var array1 = [ "a1", "b1", "b2" ]
var array2 = [ "a1", "a2" ]
//a3 variable will be used only for thirdSolution
var a3 = array1 filter (array2 contains $)
---
{
firstSolution: array1 filter !(array2 contains $) ++ (array2 filter !(array1 contains $)),
secondSolution: (array1 -- array2) ++ (array2 -- array1),
thirdSolution: flatten(array1 + array2) distinctBy ((item, index) -> item) -- a3 ,
fourthSolution: flatten(((((array1 ++ array2) groupBy $) pluck $ ) filter sizeOf($) < 2))
}