I want to superimpose two numbers on the array
const recomArr = [{ mycount: 12, myhour: 0 },
{ mycount: 5, myhour: 1 },
{ mycount: 3, myhour: 2 },
{ mycount: 3, myhour: 3 },
{ mycount: 3, myhour: 4 },
{ mycount: 1, myhour: 5 },
{ mycount: 3, myhour: 6 },
{ mycount: 0, myhour: 7 },
{ mycount: 2, myhour: 8 },
{ mycount: 2, myhour: 9 },
{ mycount: 3, myhour: 10 },
{ mycount: 2, myhour: 11 },
{ mycount: 5, myhour: 12 },
{ mycount: 4, myhour: 13 },
{ mycount: 7, myhour: 14 },
{ mycount: 39, myhour: 15 },
{ mycount: 10, myhour: 16 },
{ mycount: 8, myhour: 17 },
{ mycount: 10, myhour: 18 },
{ mycount: 8, myhour: 19 },
{ mycount: 6, myhour: 20 },
{ mycount: 8, myhour: 21 },
{ mycount: 8, myhour: 22 },
{ mycount: 16, myhour: 23 }]
console.log(recomArr.reduce((t, c) => {
if (t[0].length > 0 && (t[0].length % 2) === 0) {
t[1].push(t[0][0] + t[0][1]);
t[0] = [];
} else {
t[0].push(c.mycount)
}
return t;
}, [[], []]));
the result is wrong. I can"t figure out what went wrong