码迷,mamicode.com
首页 > 其他好文 > 详细

[Ramda] allPass, propEq

时间:2016-11-30 07:50:32      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:replace   curry   filter   blog   span   color   log   amd   map   

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

标签:replace   curry   filter   blog   span   color   log   amd   map   

原文地址:http://www.cnblogs.com/Answer1215/p/6116157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!