博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Ramda] Filter, Reject and Partition
阅读量:4922 次
发布时间:2019-06-11

本文共 943 字,大约阅读时间需要 3 分钟。

We'll learn how to get a subset of an array by specifying items to include with filter, or items to exclude using reject. We'll also look at how to get the results from both filter and reject, neatly separated with partition.

 

// we don't need to require in Plunker!//const R = require('ramda')const pets = [  {name: 'Spike', type: 'dog'},  {name: 'Mittens', type: 'cat'},  {name: 'Rover', type: 'dog'},  {name: 'Fluffy', type: 'cat'},  {name: 'Fido', type: 'dog'}]const dogCheck = pet => pet.type == 'dog'// const result = R.filter(dogCheck, pets)// const result = R.reject(dogCheck, pets)const result = R.partition(dogCheck, pets)console.log(result)document.getElementById('output').innerHTML = `${JSON.stringify(result)}`

 

/*[ [{"name":"Spike","type":"dog"},{"name":"Rover","type":"dog"}, {"name":"Fido","type":"dog"}], [{"name":"Mittens","type":"cat"},{"name":"Fluffy","type":"cat"}] ]*/

 

转载于:https://www.cnblogs.com/Answer1215/p/5902304.html

你可能感兴趣的文章
Java学习从入门到精通
查看>>
查找目录下的所有文件中是否含有某个字符串 linux
查看>>
2018年各大互联网前端面试题四(美团)
查看>>
一起学Python:字符串介绍
查看>>
学习笔记:树状数组
查看>>
洛谷P1772 [ZJOI2006]物流运输 题解
查看>>
CF519E A and B and Lecture Rooms
查看>>
python-redis之数据类型二
查看>>
Java类加载机制
查看>>
循环单链表实现
查看>>
Android设计模式实战---责任链模式
查看>>
剑指Offer_31_整数中1出现的次数(从1到n整数中1出现的次数)
查看>>
10月29日 迅雷会员vip账号分享 91freevip 晚间21:00更新
查看>>
【一题多解】Python 字符串逆序
查看>>
open ball、closed ball 与 open set、closed set(interior point,limit point)、dense set
查看>>
字典(dictionary)与映射(map)
查看>>
Python 编程规范 —— TODO 注释(结合 PyCharm)
查看>>
十万个为什么 —— 名词解释(体育)
查看>>
table的设置(w3c)
查看>>
冲刺一
查看>>