Hearted Youtube comments on Wes Bos (@WesBos) channel.
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
Good video, Wes. I think you could have simplified it a bit more. Here's my approach:
https://codepen.io/donovanperalta/pen/ZEpLLGJ
function parseArray(arr) {
const [headings, ...rows] = arr;
return rows.map((row) => {
return headings.reduce((acc, heading, i) => {
return { ...acc, [heading]: row[i] };
}, {});
});
}
const results = [arr1, arr2, arr3]
.map((arr) => parseArray(arr))
.flat()
.reduce((acc, person) => {
const index = acc.findIndex(p => p.id === person.id);
if (index > -1) {
acc[index] = { ...acc[index], ...person };
return acc;
}
return [...acc, person];
}, []);
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1