프로그래머스(JavaScript)/Lv1

[프로그래머스 : 연습문제] Lv1. 행렬의 덧셈(JavaScript)

지미지민 2024. 3. 16. 19:28

 

 

 

💜 코드


function solution(arr1, arr2) {
   let result = [];
    for(let i=0; i<arr1.length; i++){
        let row = [];
        for(let j=0; j<arr1[i].length; j++){
            row.push(arr1[i][j] + arr2[i][j]);
        }
        result.push(row);
    }
    return result;
}

 

 

 

 

💜 실행 결과


 

 

 

 

💜 다른 사람의 풀이


function sumMatrix(A,B){
    return A.map((arr1, idx1) => arr1.map((val, idx2) => val+B[idx1][idx2]));
}