[Ramda] allPass, propEq
Ramda
2023-09-14 09:00:52 时间
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] R.project -- Select a Subset of Properties from a Collection of Objects in Ramda
- [Ramda] Rewrite if..else with Ramda ifElse
- [Ramda] Getter and Setter in Ramda & lens
- [Ramda] Compose and Curry
- [Javascript] Deep merge in Javascript with Ramda.js mergeDeepWith
- [Ramda] Get Deeply Nested Properties Safely with Ramda's path and pathOr Functions
- [Ramda] Create a Query String from an Object using Ramda's toPairs function
- [Ramda] Refactor a Promise Chain to Function Composition using Ramda
- [Ramda] Refactor to a Point Free Function with Ramda's useWith Function
- [Ramda] Eliminate Function Arguments (Point-Free Style) with Ramda's Converge
- [Ramda] Simple log function for debugging Compose function / Using R.tap for logging
- [Ramda] Compose and Curry