这是输出(图片1),如果你将记录final
阵列从片段1ES6减少方法不返回所需的输出
我试图做的是减少我的数组像所显示的阵列中图像2
我已经使用lodash _.uniqBy()
[试图片段2],但仍然输出,我从日志记录reduce
变量仍然是输出从图片1。如何将我的final
阵列减少到输出图片2?
图像2
const reduce = final.reduce((x, y) => {
if (x.department !== y.department) {
return x;
}
})
console.log(final)
console.log(reduce);
片段1
_.uniqBy(final, 'department')
片段2
UPDATE
这是打字稿.ts
不.js
。
接口=>[{ department: string, professors: string[] }]
至于请求
这是我得到我的数据
[
{
department: 'Department of Mathematics - INTRAMUROS',
professors: [
'Sabino, Lilibeth D.',
'Department Chair',
.....
这是我的代码从我final
阵列到达之前
const recommend = [];
const final = [];
recommended.forEach((prof) => {
const find = proffessorDetails.find((collection) => {
return collection.professors.find((professor) => professor == prof);
});
recommend.push(find);
})
const find = recommend.map((collection) => {
return {
department: collection.department,
prof: _.intersection(collection.professors, recommended)
};
});
final.push(find);
你总是返回累加器减少功能 – MinusFour
这不是你如何使用'reduce'对象。 – str
我明白了,那么有什么可能是最好的解决方案,以减少我的最终阵列到图像2的输出? – Vadamadafaka