📌  相关文章
📜  第 11 天 2d 数组hackerrank 解决方案 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:10.385000             🧑  作者: Mango

代码示例1
// day 11 2d arrays hackerrank solution javascript
function main() {

    let arr = Array(6);
    
    for (let i = 0; i < 6; i++) {
        arr[i] = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
    }
    /* row i, column j
     * 1 1 1
     * 1 1 1
     * 1 1 1 
     */
    
    let sumArray = [];
    let max = 0;
    let index = 0;
    for(let i=0; i<4; i++){
        for(let j =0; j<4; j++){
            sumArray[index] = arr[i][j] + arr[i][j+1] + arr[i][j+2] + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
            index++
        }
    }
    max = Math.max(...sumArray);
    return console.log(max);
}