zoukankan      html  css  js  c++  java
  • [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"}]
    ]
    */
  • 相关阅读:
    JAVA队列的使用
    四种线程池的使用
    JAVA中只有值传递
    为什么说Java语言是平台无关的?
    Jsoup爬虫解析
    java爬虫
    oracle触发器
    easyUi引入方法
    highchart
    July 20th 2017 Week 29th Thursday
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5902304.html
Copyright © 2011-2022 走看看