我有这样的数据
const faq =
{
Question1:{
question:’Question1’,
answer: {
Answer1_1: {
answer: ‘Answer1_1’
},
Answer1_2: {
answer: ‘Answer1_2’
}
}
},
Question2:{
question:’Question2’,
answer: {
Answer2_1: {
answer: ‘Answer2_1’
},
Answer2_2: {
answer: ‘Answer2_2’
}
}
}
}
我想要的预期结果是
[
{
question: ’Question1’
answer: [‘Answer1_1’, ‘Answer1_2’]
},
{
question: ’Question2’
answer: [‘Answer2_1’, ‘Answer2_2’]
}
]
据我了解,我做了一个这样的函数:
const convertQuestionTypesToMap = compose(
reduce(
(map, {question, answer}) => ({...map, [question]: question}),
{}
),
map(([question, value]) => value),
toEntries
);
我没有得到预期的结果。谁能纠正我的功能?