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