【发布时间】:2020-07-27 12:55:58
【问题描述】:
我想转换以下内容以使其可重用/通用。具体来说,我不确定采用什么方法来参数化过滤器评估的右侧。
这是我目前所拥有的,适用于以下用例。我正在尝试将咖喱部分转换为这样的东西......
const filterProcess = theFilter => theData => theFilter === ${dataBranch}.${dataLeaf}
我当前的工作用例。
const hotelList = [
{city: "London", hotel: 1},
{city: "Prague", hotel: 1},
{city: "London", hotel: 2},
{city: "Prague", hotel: 2},
]
const isLocated = location => hotels => location === hotels.city
const hotelsIn = hotelList.filter(isLocated(location));
console.log(hotelsIn('London'))
【问题讨论】:
标签: javascript functional-programming currying