Sitemap
Arindam Goswami

Arindam Goswami

I am a software Engineer having 14+ years of rich expertise on various IT application e.g - of working on Java , middleware and backend technologies.

Dataweave practise set 1

Aug 16, 2024

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

--

--

Arindam Goswami
Arindam Goswami

Written by Arindam Goswami

I am a software Engineer having 14+ years of rich expertise on various IT application e.g - of working on Java , middleware and backend technologies.