const array = [
[
{ name: 'A', age: 10 },
{ name: 'B', age: 10 },
{ name: 'A', age: 10 },
{ name: 'B', age: 10 },
],
[
{ name: 'C', age: 10 },
{ name: 'D', age: 10 },
{ name: 'C', age: 10 },
{ name: 'D', age: 10 },
],
];
const groupBy = arr => {
const cache = new Map();
for (const item of arr.flat(1)) {
if (!cache.has(item.name)) {
const group = [];
cache.set(item.name, group);
}
cache.get(item.name).push(item);
}
return [...cache.values()];
}
console.log(groupBy(array))
let data = [[1, 2, '3'], ['5', 2]];
const sums = data.map( arr => arr.reduce( (acc, value) => acc + value, 0));
console.log(sums ) // ["33", "052"]
//исправить можно так
const sums = data.map( arr => arr.reduce( (acc, value) => +value + acc, 0));
console.log(sums ) // [6, 7]
// или
const sums = data.map( arr => eval(arr.join('+')))
console.log(sums ) // [6, 7]