gpt4 book ai didi

javascript - 的作用是什么?和 : mean in these one line return statements?

转载 作者:行者123 更新时间:2023-12-03 05:12:16 24 4
gpt4 key购买 nike

试图弄清楚什么是? and : 表示这一行 return 语句。

return input && input.length ? [input.filter(p => p > 0).length, input.filter(n => n < 0).reduce((a, b) => a + b, 0)] : [];

最佳答案

这是一个三元 if 语句,为了组织起见,我会使用括号,但它的工作原理如下:

[条件] ? [如果条件为真则返回] : [如果条件为假则返回]

关于javascript - 的作用是什么?和 : mean in these one line return statements?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41755558/

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