Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fun_11() {
- var array = [
- [1, 2, 3, 4],
- [5, 6, 7, 8],
- [9, 10, 11, 12],
- [13, 14, 15, 16]
- ];
- function recursiveLineSum(arr, row, maxRowSum) {
- var sum = 0;
- if (row >= arr.length) {
- return maxRowSum;
- }
- arr[row].forEach(function (element) {
- sum += element;
- });
- if (sum > maxRowSum) {
- maxRowSum = sum;
- }
- return recursiveLineSum(arr, row + 1, maxRowSum);
- }
- function recursiveColSum(arr, column, maxColSum) {
- var i = 0,
- tempSum = 0;
- if (column >= arr.length) {
- return maxColSum;
- }
- for (; i < arr.length; i += 1) {
- tempSum += arr[i][column];
- }
- if (tempSum >= maxColSum) {
- maxColSum = tempSum;
- }
- return recursiveColSum(arr, column + 1, maxColSum);
- }
- console.log(recursiveLineSum(array, 0, 0));
- console.log(recursiveColSum(array, 0, 0));
- }
- fun_11();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement