1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
function slice_origin(arr){ var sum = 0 ; for(var x=0; x<arr.length-3; x++){ for(var y=0; y<arr.length-2; y++){ for(var z=0; z<arr.length-1; z++){ if(x<y && y<z){ var temp_sum = sums(x,y,z,arr); if(sum < temp_sum){ sum = temp_sum; console.log("==="); console.log("sum"+sum); console.log("==="); console.log(x,y,z); console.log("==="); } } } } } function sums(x,y,z,arr){ var sum = 0; var xy = arr.slice(x+1,y); for(var i=0; i<xy.length; i++){ sum += xy[i]; } var yz = arr.slice(y+1,z); for(var j=0; j<yz.length; j++){ sum += yz[j]; } return sum; } } var arr = [-3,-1,10,-6,-3,4,5,-1,-5,-1,5,4,1,-5,-1,-5,-11111,-2,0,-9,-10,14,1,-1]; slice_origin(arr);
|