We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d93bed0 commit 6ee0fd3Copy full SHA for 6ee0fd3
matrix-addition.js
@@ -0,0 +1,36 @@
1
+// kata - https://www.codewars.com/kata/526233aefd4764272800036f
2
+
3
+// Input - 2 matrices N * N sized (square)
4
+// Ouput - N * N matrix with the sum of the 2 matrcies
5
6
+const matrixAddition = (a, b) => {
7
+ const c = Array.from({ length: a.length }, (x) => Array.from({ length: a.length }));
8
+ for (let x = 0; x < a.length; x++) {
9
+ for (let y = 0; y < a.length; y++) {
10
+ c[x][y] = a[x][y] + b[x][y];
11
+ }
12
13
+ return c;
14
+};
15
16
+console.log(
17
+ matrixAddition(
18
+ [
19
+ [1, 2, 3],
20
+ [3, 2, 1],
21
+ [1, 1, 1],
22
+ ],
23
+ // +
24
25
+ [2, 2, 1],
26
+ [3, 2, 3],
27
+ [1, 1, 3],
28
+ ]
29
+ ),
30
+ '\n',
31
32
+ [3, 4, 4],
33
+ [6, 4, 4],
34
+ [2, 2, 4],
35
36
+);
0 commit comments