gpt4 book ai didi

Dataweave 2.2 takeWhile和filter有什么区别?

转载 作者:行者123 更新时间:2023-12-04 00:20:45 24 4
gpt4 key购买 nike

%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,4,3]
---
arr filter $ <= 2

%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,4,3]
---
arr takeWhile $ <= 2

它们都给出相同的结果。有什么区别吗?

最佳答案

嗨,戴尔,有一个区别 takeWhile 将停止获取第一个不满足条件的元素,这不是过滤器的情况,所以对于这个例子 [0,2,4,3,1]

使用 TakeWhile

%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,2,4,3,1]
---
arr takeWhile $ <= 2

返回:

[
0,
2
]

带过滤器

%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,2,4,3,1]
---
arr filter $ <= 2

返回:

[
0,
2,
1
]

关于Dataweave 2.2 takeWhile和filter有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60875348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com