From f5d59b5f114e616a930a63cea0e840d4f8e8499d Mon Sep 17 00:00:00 2001 From: jungmyunggi <143400940+jungmyunggi@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:30:16 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8?= =?UTF-8?q?=EC=8A=A4=20-=20Lv.=202]=20=ED=96=89=EB=A0=AC=EC=9D=98=20?= =?UTF-8?q?=EA=B3=B1=EC=85=88=EC=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jungmyunggi/Multiplication Of Matrices.js | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 jungmyunggi/Multiplication Of Matrices.js diff --git a/jungmyunggi/Multiplication Of Matrices.js b/jungmyunggi/Multiplication Of Matrices.js new file mode 100644 index 0000000..7e9efe5 --- /dev/null +++ b/jungmyunggi/Multiplication Of Matrices.js @@ -0,0 +1,34 @@ +arr1 = [ + [2, 3, 2], + [4, 2, 4], + [3, 1, 4], +]; +arr2 = [ + [5, 4, 3], + [2, 4, 1], + [3, 1, 1], +]; + +function solution(arr1, arr2) { + var answer = [[]]; + const r1 = arr1.length; + const c1 = arr1[0].length; + const r2 = arr2.length; + const c2 = arr2[0].length; + const temp = []; + for (let i = 0; i < r1; i++) { + temp.push(new Array(c2).fill(0)); + } + + for (let i = 0; i < r1; i++) { + for (let j = 0; j < c2; j++) { + for (let k = 0; k < c1; k++) { + temp[i][j] += arr1[i][k] * arr2[k][j]; + } + } + } + answer = [...temp]; + return answer; +} + +console.log(solution(arr1, arr2));