I would like to know how to find greater number in an array,
I have array arr
and num
denotes the consective number to be taken
in this case, 2+3, 5+6, 1+4
sumMethod([2,3,5,6,1,4],2)
in this case, 2+3+5, 6+2+4
sumMethod([2,3,5,6,2,4],3)
return the greater element in array.
function sumMethod(arr, num){
for(var i=0;i<arr.length;i+num){
for(var j=i;j<num;j++){
//stuck
}
}
}
Expected Output,
case1:
11
case2:
12