Dataweave practise set 1
Find a occurrence of an element in an array
Input
[1,2,3,4,5,1]Output
{
"itemNo": 1,
"presen": "duplicate"
},
{
"itemNo": 2,
"presen": "duplicate"
},
{
"itemNo": 3,
"presen": "single"
},
{
"itemNo": 1,
"presen": "duplicate"
},
{
"itemNo": 2,
"presen": "duplicate"
},
{
"itemNo": 2,
"presen": "duplicate"
}
]Dataweave code
%dw 2.0
output application/json
var myarra = payload
var counter:Number = 0
fun myOccuranceCheckFunction(myno:Number) =
sum((myarra map ((item, index) -> if(myno == item) log(counter + 1) else counter
)))
- -
payload map ((item, index) -> {"itemNo" : item ,
"presen" : if (myOccuranceCheckFunction(item) > 1 ) "duplicate" else "single"}
)Find the common element present in both array
Get Arindam Goswami’s stories in your inbox
Join Medium for free to get updates from this writer.
Input Data
array1 = [12,34,45,15,89]
array2 = [15,6,8,9,20,30,34]
Output Data
[15,34]Dataweave Code








