Is there a way to modify the code below to allow for adding an arbitrary number of arrays as arguments? For instance, how can I adjust it so that ([1, 2, 3], [4, 5], [6]) would result in an array of [11, 7, 3]?
function addArrays(...arrays) {
let result = new Array(Math.max(...arrays.map(arr => arr.length))).fill(0);
arrays.forEach((arr) => {
arr.forEach((num, index) => {
result[index] += num;
});
});
return result;
}