javascript - Filter collection based on values in array in Ramda - Stack Overflow

PHOTO EMBED

Thu Aug 05 2021 10:40:47 GMT+0000 (Coordinated Universal Time)

Saved by @huttyman #javascript

const {curry, filter, contains, prop} = R

const collection = [{ type: 1, eyes: 'blue'},{ type: 2, eyes: 'brown'}, { type: 3, eyes: 'green'}, { type: 4, eyes: 'blue'}]
const array = [1, 2, 4]

const filterBy = curry((propName, selectedValues, collection) => 
  filter(e => contains(prop(propName, e), selectedValues), collection))

const newCollection = filterBy('type', array, collection)

console.log(newCollection)
content_copyCOPY

https://stackoverflow.com/questions/50161078/filter-collection-based-on-values-in-array-in-ramda