mule - 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.
解决方案
正如@George 提到的一个简单的 orderBy 解决了我的问题
import diff from dw::util::Diff
%dw 2.0
output application/json
---
{
result: diff(payload.array orderBy $, vars.array orderBy $).matches
}
解决了这个问题。
推荐阅读
- ios - KingFisher SwiftUI cancelOnDisappear 方法似乎不会阻止或取消 ScrollView 中的调用
- javascript - 使用反应钩子根据缩略图更新产品图像
- javascript - 在本机反应中安排本地通知不起作用
- python - VerneMQ single publish messages lost when client is offline
- react-native - 在功能组件中反应原生响应式布局
- flutter - Flutter VScode 保存到自动重启
- django - 使用 Django + Gunicorn 在根/主页上的 nginx 404
- xamarin - 在 Xamarin 项目中找不到 FilePicker 类
- google-sheets - 正则表达式提取两个分数谷歌表之间的数字
- powershell - PowerShell HTML 元素变量