const arr = [
[2, 2, 3, 9, 7],
[6, 2, 4, 5, 8],
];
const baseArr = [
[2, 2, 3, 9, 7],
[6, 2, 4, 5, 8],
];
const multDoubles = (arr) => {
const counted = arr.reduce((acc, num, i) => {
if(acc.has(num)) {
acc.get(num).push(i);
return acc;
}
acc.set(num, [i]);
return acc;
}, new Map);
const multedArr = [...arr];
counted.forEach((indexes, num) => {
if(indexes.length > 1) {
const newNum = num * indexes.length;
indexes.forEach((i) => {
multedArr[i] = newNum;
})
}
});
return multedArr;
};
const result = baseArr.map((arr) => multDoubles(arr));