[Ramda] allPass, propEq
const needs = ['wifi', 'shower', 'laundry']; const homes = [{
name: 'Home 1',
wifi: 'y',
shower: 'y',
laundry: 'y',
metro: 'n',
balcony: 'y',
fireplace: 'n',
pool: 'y'
}, {
name: 'Home 2',
wifi: 'n',
shower: 'y',
laundry: 'y',
metro: 'n',
balcony: 'n',
fireplace: 'n',
pool: 'n'
}, {
name: 'Home 3',
wifi: 'y',
shower: 'y',
laundry: 'y',
metro: 'n',
balcony: 'y',
fireplace: 'y',
pool: 'n'
}, {
name: 'Home 4',
wifi: 'y',
shower: 'y',
laundry: 'n',
metro: 'n',
balcony: 'n',
fireplace: 'n',
pool: 'n'
}]; const propMatch = R.curry((toMatch, prop) => R.propEq(prop, toMatch));
const needsCheck = R.map(propMatch('y'), needs);
const allNeedsMatch = R.allPass(needsCheck);
const res = R.filter(allNeedsMatch, homes);
console.log(res)
[Ramda] allPass, propEq的更多相关文章
- [Ramda] Filter an Array Based on Multiple Predicates with Ramda's allPass Function
In this lesson, we'll filter a list of objects based on multiple conditions and we'll use Ramda's al ...
- [转] Ramda 函数库参考教程
学习函数式编程的过程中,我接触到了 Ramda.js. 我发现,这是一个很重要的库,提供了许多有用的方法,每个 JavaScript 程序员都应该掌握这个工具. 你可能会问,Underscore 和 ...
- [Ramda] Handle Branching Logic with Ramda's Conditional Functions
When you want to build your logic with small, composable functions you need a functional way to hand ...
- [Ramda] Refactor a Promise Chain to Function Composition using Ramda
Promise chains can be a powerful way to handle a series of transformations to the results of an asyn ...
- [Ramda] Refactor to a Point Free Function with Ramda's useWith Function
Naming things is hard and arguments in generic utility functions are no exception. Making functions ...
- [Ramda] Filter, Reject and Partition
We'll learn how to get a subset of an array by specifying items to include with filter, or items to ...
- [Ramada] Build a Functional Pipeline with Ramda.js
We'll learn how to take advantage of Ramda's automatic function currying and data-last argument orde ...
- 从函数式编程到Ramda函数库(二)
Ramda 基本的数据结构都是原生 JavaScript 对象,我们常用的集合是 JavaScript 的数组.Ramda 还保留了许多其他原生 JavaScript 特性,例如,函数是具有属性的对象 ...
- 从函数式编程到Ramda函数库(一)
函数式编程是种编程方式,它将电脑运算视为函数的计算.函数编程语言最重要的基础是λ演算(lambda calculus),而且λ演算的函数可以接受函数当作输入(参数)和输出(返回值).和指令式编程相比, ...
随机推荐
- checkbox-padding 调整checkbox字体跟图标距离
有时候我们会遇到需要调整控件中的内容相对于容器的位置.这里有两种情况 1.linearlayout这样的容器中,包含button类的控件,这时候margin可以调节 2.textview中的文字内容 ...
- COGS——T 1786. 韩信点兵
http://www.cogs.pro/cogs/problem/problem.php?pid=1786 ★★★ 输入文件:HanXin.in 输出文件:HanXin.out 简单对比时 ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- 利用formdata对象上传文件时,需要添加的参数
function doUpload() { var formData = new FormData($( "#uploadForm" )[0]); $.ajax({ url: 'h ...
- scrapy-爬取斗图
scrapy-爬取斗图代码 <一> 开局三连杀 1.创建run的文件
- jedate-开始使用一款好用的时间插件
jeDate日期控件 -(原生JS版)jeDate V6.5.0 是一款原生JS开发的 不依赖任何第三方库 大众化的日期控件,包含 多语言.设定年月(YYYY-MM).日期范围限制.开始日期设定.自定 ...
- java线程——详解Callable、Future和FutureTask
回顾: 接上篇博客 java线程--三种创建线程的方式,这篇博客主要介绍第三种方式Callable和Future.比较继承Thread类和实现Runnable接口,接口更加灵活,使用更广泛.但这两种方 ...
- amazeui页面分析之登录页面
amazeui页面分析之登录页面 一.总结 1.tpl命名空间:tpl命名空间的样式都是从app.css里面来的,app.css用用来移动网站开发的样式 2.表单样式:am-form到am-form- ...
- UVA 11584 - Partitioning by Palindromes DP
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- NDIS
NDIS NDIS(NetworkDriverInterfaceSpecification)是网络驱动程序接口规范的简称.它横跨传输层.网络层和数据 链路层,定义了网卡或网卡驱动程序与上层协议驱动程序 ...