let arr = [1,2,5,4,6,3] function maxNum (arr, n) { let max = 0 for (let i = 0; i<arr.length;i++){ let curNum = 0 for (let j=i;j<(n+i);j++){ curNum += arr[j] } if (curNum > max) { max = curNum } } return max } console.log(maxNum(arr,2))