[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 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"}]]
*/
时间: 2024-12-14 04:38:46

[Ramda] Filter, Reject and Partition的相关文章

Underscore.js find filter reject where where

_.find(); _.find(list, predicate, [context]); 在list中逐项查找,返回第一个通过predicate迭代函数真值检测的元素值.找到匹配元素立即返回,不会遍历整个list _.filter() _.filter(list, predicate, [context]); 遍历数组中的每个值,返回包含predicate迭代函数真值得所有元素值; _.reject(); _.reject(list, predicate, [context]); 返回list

underscore中文api (1.8.2)

Underscore一个JavaScript实用库,提供了一整套函数式编程的实用功能,但是没有扩展任何JavaScript内置对象.它是这个问题的答案:“如果我在一个空白的HTML页面前坐下, 并希望立即开始工作, 我需要什么?“...它弥补了部分jQuery没有实现的功能,同时又是Backbone.js必不可少的部分. (感谢@小邓子daj的翻译建议) Underscore提供了100多个函数,包括常用的: map, filter, invoke — 当然还有更多专业的辅助函数,如:函数绑定,

分区扫描执行计划分析简介

SQL> select * from v$version; BANNER--------------------------------------------------------------------------------Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64biPL/SQL Release 10.2.0.5.0 - ProductionCORE    10.2.0.5.0      Producti

用实例理解Storm的Stream概念

原文首发在个人博客:http://zqhxuyuan.github.io/2016/06/30/Hello-Storm/ 如需转载,请注明出处,谢谢! 缘起 事情源于在看基于Storm的CEP引擎:flowmix 的FlowmixBuilder代码, 每个Bolt设置了这么多的Group, 而且declareStream也声明了这么多的stream-id, 对于只写过WordCountTopology的小白而言, 直接懵逼了,没见过这么用的啊,我承认一开始是拒绝的,每个Bolt都设置了这么多Gr

用Merge来改写相关更新的例子

下面的两个SQL是等价的,但是一个执行N小时都执行不完,一个花了一分钟. 执行计划显示第一个语句是由外面的即将被更新的表驱动内层,相对于是一个NEST LOOP,cost非常大.第二个语句是内层单独执行完后,与外面的筛选结果做一个HASH JOIN, cost降低了很多. UPDATE GPCOMP1.GPRECL R SET (PROMISED_BY,PROMISED_DATE)=(SELECT W.USER_ID,W.CREATED_ON FROM (SELECT T.*,ROWNUM FR

merge into sql优化

今天网友说他的merge into sql跑了15分钟了还没有跑出数据,问我能不能优化一下,我让他把sql和sql的执行计划发过来 merge into F_Sal_P_Camp_Samp_Cust_Data A using (select CUST_ID, CUST_MNGR_ID, ORGCODE From ( SELECT t.CUST_ID, t.CUST_MNGR_ID, t.ORGCODE, ROW_NUMBER() OVER(PARTITION BY t.cust_id ORDER

iptables包过滤入门指南

1. Introduction Welcome, gentle reader. It is assumed you know what an IP address, a network address, a netmask, routing and DNS are. If not, I recommend that you read the Network Concepts HOWTO. This HOWTO flips between a gentle introduction (which

10.15 iptables filter表案例 10.16/10.17/10.18 iptables nat表应用

10.15 iptables filter表案例 10.16/10.17/10.18 iptables nat表应用 扩展 iptables应用在一个网段 http://www.aminglinux.com/bbs/thread-177-1-1.html sant,dnat,masquerade http://www.aminglinux.com/bbs/thread-7255-1-1.html iptables限制syn速率 http://www.aminglinux.com/bbs/thre

x264源代码简单分析:滤波(Filter)

本文记录x264的x264_slice_write()函数中调用的x264_fdec_filter_row()的源代码.x264_fdec_filter_row()对应着x264中的滤波模块.滤波模块主要完成了下面3个方面的功能: (1)环路滤波(去块效应滤波)(2)半像素内插(3)视频质量指标PSNR和SSIM的计算 本文分别记录上述3个方面的源代码. 函数调用关系图 滤波(Filter)部分的源代码在整个x264中的位置如下图所示. 单击查看更清晰的图片 滤波(Filter)部分的函数调用关