How can I map an array of ids:
['a', 'b', 'c']
to their corresponding objects in another array:
[
{
id: 'a',
label: 'Letter A'
},
{
id: 'b',
label: 'Letter B'
},
...
...
]
The other array is likely to have more objects than the first array has ids.
The challenging part is that I want to do this the "Ramda way".
If I were not using RamdaJS, it would look like this:
const ids = ['a', 'b']
const objects = [{ id: 'a', label: 'Letter A' }, { id: 'b', label: 'Letter B' }, { id: 'c', label: 'Letter C' }]
const whatIWant = objects.filter(obj => ids.includes(obj.id))
There must be a way to do this with a combination of map
, filter
, prop
, propEq
, isNil
, reject
, etc. I just can't seem to figure it out.
"Keep/filter the objects who have ids included in the ids array"
I know the following code doesn't work, but this is sort of how far I got:
const doFilter = (ids, objects) => (
map(
find(
// ??? Where the object.id is included in ids[]
)(objects)
)(ids)
)
Thanks