Skip to content

Commit 2360efc

Browse files
committed
행렬의 곱셈, 심화
1 parent a3b4f62 commit 2360efc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function solution(arr1, arr2) {
2+
const n = arr1.length;
3+
const m = arr2[0].length;
4+
5+
const answer = Array.from({ length: n }, () => Array(m).fill(0));
6+
7+
for (let i = 0; i < n; i++) {
8+
for (let j = 0; j < m; j++) {
9+
const result = arr1[i].reduce((acc, cur, idx) => acc + cur * arr2[idx][j], 0);
10+
11+
answer[i][j] = result;
12+
}
13+
}
14+
15+
return answer;
16+
}
17+
18+
console.log(
19+
solution(
20+
[
21+
[2, 3, 2],
22+
[4, 2, 4],
23+
[3, 1, 4],
24+
],
25+
[
26+
[5, 4, 3],
27+
[2, 4, 1],
28+
[3, 1, 1],
29+
]
30+
)
31+
);

0 commit comments

Comments
 (0)