I'm trying to write code using Ramda to produce a new data structure, using only the id
and comment
keys of the original objects. I'm new to Ramda and it's giving me some fits, although I have experience with what I think is similar coding with Python.
Given the following initial data structure…
const commentData = {
'30': {'id': 6, 'comment': 'fubar', 'other': 7},
'34': {'id': 8, 'comment': 'snafu', 'other': 6},
'37': {'id': 9, 'comment': 'tarfu', 'other': 42}
};
I want to transform it into this…
{
'6': 'fubar',
'8': 'snafu',
'9': 'tarfu'
}
I found the following example in the Ramda cookbook that comes close…
const objFromListWith = R.curry((fn, list) => R.chain(R.zipObj, R.map(fn))(list));
objFromListWith(R.prop('id'), R.values(commentData));
But values it returns includes the whole original object as the values…
{
6: {id: 6, comment: "fubar", other: 7},
8: {id: 8, comment: "snafu", other: 6},
9: {id: 9, comment: "tarfu", other: 42}
}
How can I reduce the values down to the value of their comment
key only?
I don't need to use the code I got from the cookbook. If anyone can suggest some code that will give the results I'm looking for that's also better (simpler, shorter, or more efficient) than the example here, I'll be happy to use that instead.