2
inputArray = ["cat", "bat", "mat"]  
configuredArray = ["dog", "elephant", "fox", "cat"]

inputArray and configuredArray are variable length String arrays.

If any one element of the inputArray is present in the configuredArray I would like to set a bloolean flag. How do I write it in Dataweave 2.0? Thanks in advance.

DuDa
  • 3,718
  • 4
  • 16
  • 36
jpass abba
  • 21
  • 2

3 Answers3

7

You could leverage the filter and contains functions and do something like this. Also leaves you with a reusable functin.

%dw 2.0
output application/json

fun any(left: Array, right: Array) =
    sizeOf(left filter (right contains $)) > 0

---
["cat", "bat", "mat"] any ["dog", "elephant", "fox", "cat"]
Michael Jones
  • 1,900
  • 5
  • 12
0
%dw 2.0
output application/json
var arr1 = ["cat", "bat", "mat"]
var arr2 = ["dog", "elephant", "fox", "cat"]

---
sizeOf(arr1 reduce (item, acc = []) -> if (arr2 contains item) acc + item else acc) >0
Salim Khan
  • 4,233
  • 11
  • 15
0

Perform -- operation between the arrays and based on difference in size, we can easily evaluate it.

%dw 2.0
output application/json
var inputArray = ["cat", "bat", "mat"]  
var configuredArray = ["dog", "elephant", "fox", "cat"]
---
{
   match : (sizeOf(inputArray -- configuredArray) < sizeOf(inputArray))
}