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的更多相关文章

  1. [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 ...

  2. [转] Ramda 函数库参考教程

    学习函数式编程的过程中,我接触到了 Ramda.js. 我发现,这是一个很重要的库,提供了许多有用的方法,每个 JavaScript 程序员都应该掌握这个工具. 你可能会问,Underscore 和  ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. [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 ...

  8. 从函数式编程到Ramda函数库(二)

    Ramda 基本的数据结构都是原生 JavaScript 对象,我们常用的集合是 JavaScript 的数组.Ramda 还保留了许多其他原生 JavaScript 特性,例如,函数是具有属性的对象 ...

  9. 从函数式编程到Ramda函数库(一)

    函数式编程是种编程方式,它将电脑运算视为函数的计算.函数编程语言最重要的基础是λ演算(lambda calculus),而且λ演算的函数可以接受函数当作输入(参数)和输出(返回值).和指令式编程相比, ...

随机推荐

  1. js19--继承终极版本

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  2. system.setting-全局变量数据监听

    今天在setting里添加了一个新的变量,想要实现对这个变量的监听.现在记录下方法 首先就是明白一点,我们在system.setting里添加的变量,都会被保存在data/data/com.andro ...

  3. ubuntu-文件管理、编辑

    1.创建单层文件夹 mkdir test 如果你想要创建多层文件夹,这时候你需要添加一个参数-p mkdir -p t1/t2/t3 如果你不加-p的话,它会提示说找不到目录 2.分屏查看内容 mor ...

  4. Monkey测试执行指导

    1.Monkey常规测试

  5. javafx spring

    javafx spring http://files.cnblogs.com/files/rojas/airhacks_control.zip

  6. 失去偏执的苹果会如何?Android 会一统天下吗?

    第 一次听到Apple你绝对不会想到和手机相关.但就是这样一个不相关的东西,彻彻底底的改变了我们这个世界.说起苹果那就得必须说到乔帮主,由于苹果仅仅属于Steve jobs. 乔布斯天生聪颖.初二測得 ...

  7. matlab 局部特征检测与提取(问题与特征)

    物体识别:SIFT 特征: 人脸识别:LBP 特征: 行人检测:HOG 特征: 0. 常见手工设计的低级别特征 manually designed low-level features 语音:高斯混合 ...

  8. 1.15 Python基础知识 - 函数

    函数是可重用的程序代码段. 一.函数的声明和调用 声明格式: def 函数名([形参列表]): 函数体 调用格式: 函数名([实参列表]) 函数名:是一种标识符,命名规则为全小写字母,可以使用下划线增 ...

  9. solr6.3+tomcat8报错HTTP Status 403 – Forbidden解决办法

    注释掉tomcat下solr项目web.xml中的如下这段代码即可:

  10. [python]-类与对象-上

    [类]是一个函数包.类中可以放置函数和变量,然后类中的函数可以很方便的使用类中的变量 1.类的定义 2.类中方法的调用 在类中被定义的函数被称为类的[方法],描述的是这个类能做什么.我们使用类名.函数 ...