gpt4 book ai didi

javascript - Ramda R.pickBy R.identity 包括 zeros 0

转载 作者:行者123 更新时间:2023-11-29 18:57:36 24 4
gpt4 key购买 nike

一个简单的问题,我如何通过管道传递 pickBy 身份并包含值为零的 Prop 。目前这个例子会省略零

let linkType = { 
name: 'zac',
money: 0,
problems: 'as much as the money'
}
let linksList = R.pipe(
R.pickBy(R.identity),
)(linkType);

最佳答案

使用R.eitherR.equal(0)如果值等于 0,则得到 true,以及 R.identity 的结果如果不是:

const linkType = {
name: 'zac',
money: 0,
problems: 'as much as the money',
another: false
}

const linksList = R.pickBy(R.either(R.equals(0), R.identity))(linkType);

console.log(linksList);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>

关于javascript - Ramda R.pickBy R.identity 包括 zeros 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48667172/

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