-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.js
42 lines (33 loc) · 874 Bytes
/
matrix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Matrix {
constructor(row, column) {
this.row = row;
this.column = column;
this.data = [[]];
}
sumScalar(scalar) {
let dataSummed = [[]];
this.data.forEach((row, i) => {
dataSummed[i] = [];
row.forEach((el, j) => {
dataSummed[i][j] = el + scalar;
});
});
let matrix = new Matrix(this.row, this.column);
matrix.data = dataSummed;
return matrix;
}
add(m2) {
let m3 = new Matrix(this.row, this.column);
if(!m2 || !m2.data) {
throw 'WRONG_INFO';
}
m2.data.forEach((row, i) => {
m3.data[i] = [];
row.forEach((el, j) => {
m3.data[i][j] = this.data[i][j] + el;
});
})
return m3;
}
}
module.exports = Matrix;