Final answer:
To calculate the sum of each row in an array, create a function that iterates over the rows to sum their elements and stores these sums in a list, then returns that list.
Step-by-step explanation:
To write a function that calculates the sum of each row in an array, we can loop through each row, compute the sum, and store it in a list. The programming language wasn't specified, but here's a general structure that should help you write the function in many languages:
function sumOfRows(array) {
var rowSums = [];
for (var i = 0; i < array.length; i++) {
var sum = 0;
for (var j = 0; j < array[i].length; j++) {
sum += array[i][j];
}
rowSums.push(sum);
}
return rowSums;
}
This function initializes an empty list rowSums, then iterates through each row of the input array, summing the elements in that row and appending the sum to the rowSums list. Finally, it returns rowSums, which contains the sum of each row.