-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2491e0
commit f5d59b5
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |