Advertisement
enevlogiev

rec

Apr 16th, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fun_11(){
  2.     var arr = [
  3.         [1,2,3,4],
  4.         [5,6,7,8],
  5.         [9,10,11,12],
  6.         [13,14,15,16]
  7.     ];
  8.  
  9.     var maxRowSum = 0;
  10.     var i = 0;
  11.  
  12.     var j = 0;
  13.     var maxColSum = 0;
  14.  
  15.  
  16.     function recursiveLineSum(arr, i){
  17.         if( i >= arr.length ){
  18.             //console.log(maxRowSum);
  19.             return;
  20.         }
  21.  
  22.         var sum = 0;
  23.  
  24.         arr[i].map(function (e) {
  25.             return sum += e;
  26.         });
  27.  
  28.         if(sum > maxRowSum){
  29.             maxRowSum = sum;
  30.         }
  31.  
  32.         recursiveLineSum(arr, i + 1);
  33.     }
  34.  
  35.  
  36.  
  37.     function recursiveColSum(arr, j){
  38.         if( j >= arr.length ){
  39.             //console.log(maxColSum);
  40.             return;
  41.         }
  42.  
  43.         var tempSum = 0;
  44.  
  45.         for(var i = 0; i < arr.length; i++){
  46.             tempSum += arr[i][j];
  47.         }
  48.  
  49.         if(tempSum >= maxColSum)
  50.             maxColSum = tempSum;
  51.  
  52.  
  53.         recursiveColSum(arr, j + 1);
  54.     }
  55.  
  56.     recursiveLineSum(arr, i);
  57.     recursiveColSum(arr,j);
  58.     console.log(maxRowSum);
  59.     console.log(maxColSum);
  60.  
  61. }
  62.  
  63. fun_11();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement