Skip to content

Commit c1ba15d

Browse files
Add 1 solution.
1 parent 5326b59 commit c1ba15d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

level-2/행렬의-곱셈.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - codeisneverodd
4+
function solution(arr1, arr2) {
5+
const [row, col] = [arr1.length, arr2[0].length]
6+
let answer = new Array(row);
7+
for (let i = 0; i < row; i++) answer[i] = new Array(col)
8+
//arr1의 열의 개수 = arr2의 행의 개수, arr1의 i번째 행과 arr2의 j번째 열의 원소들을 곱한 것들의 합이 answer[i][j] 값
9+
for (let i = 0; i < row; i++) {
10+
for (let j = 0; j < col; j++) {
11+
answer[i][j] = arr1[i].reduce((sum, arr1Value, rowIndex) => sum + arr1Value * arr2[rowIndex][j], 0)
12+
}
13+
}
14+
return answer;
15+
}

0 commit comments

Comments
 (0)