SOURCE

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))
console 命令行工具 X clear

                    
>
console