首页 > 解决方案 > compare two arrays in dataweave2.0

问题描述

i want code to compare two arrays and determine if they are equal or not irrespective of their order

[a,b,c] compared to [a, b,c ] should be true [a,b,c] compare to [a,c,b] should be true as well.

i tried using the diff function from dataweave 2.0 but it works only if the parameters are Json objects not for arrays.

标签: muledataweave

解决方案


正如@George 提到的一个简单的 orderBy 解决了我的问题

import diff from dw::util::Diff
%dw 2.0
output application/json
---
{

  result: diff(payload.array orderBy  $, vars.array orderBy $).matches


}

解决了这个问题。


推荐阅读