zoukankan      html  css  js  c++  java
  • [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)
  • 相关阅读:
    事务与锁的一些总结
    NYOJ 73
    NYOJ 456
    Sleep函数
    NYOJ 488(素数环)
    NYOJ 308
    NYOJ 27
    NYOJ 325
    NYOJ 138
    求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6116157.html
Copyright © 2011-2022 走看看