You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// MatrixCheck tests to see if all of the rows of the matrix inputted have similar size columns
3
-
constmatrixCheck=(matrix)=>{
4
-
letcolumnNumb;
5
-
for(letindex=0;index<matrix.length;index++){
6
-
if(index==0){
7
-
columnNumb=matrix[index].length;
8
-
}elseif(matrix[index].length!=columnNumb){
3
+
constmatrixCheck=(matrix)=>{
4
+
letcolumnNumb
5
+
for(letindex=0;index<matrix.length;index++){
6
+
if(index===0){
7
+
columnNumb=matrix[index].length
8
+
}elseif(matrix[index].length!==columnNumb){
9
9
console.log('The columns in this array are not equal')
10
10
}else{
11
-
returncolumnNumb;
11
+
returncolumnNumb
12
12
}
13
13
}
14
14
}
15
15
16
16
// tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vise versa.
console.log('These matrices do not have a common side')
21
+
returnfalse
22
+
}else{
23
+
returntrue
24
+
}
25
25
}
26
26
27
27
// returns an empty array that has the same number of rows as the left matrix being multiplied.
28
-
//Uses Array.prototype.map() to loop over the first (or left) matrix and returns an empty array on each iteration.
29
-
constinitiateEmptyArray=(first,second)=>{
30
-
if(twoMatricesCheck(first,second)){
31
-
constemptyArray=first.map(()=>{
32
-
return[''];
28
+
// Uses Array.prototype.map() to loop over the first (or left) matrix and returns an empty array on each iteration.
29
+
constinitiateEmptyArray=(first,second)=>{
30
+
if(twoMatricesCheck(first,second)){
31
+
constemptyArray=first.map(()=>{
32
+
return['']
33
33
})
34
-
returnemptyArray;
35
-
}else{
36
-
returnfalse;
34
+
returnemptyArray
35
+
}else{
36
+
returnfalse
37
37
}
38
38
}
39
39
40
40
// Finally, `matrixMult` uses `Array.prototype.push()`, multiple layers of nested `for` loops, the addition assignment `+=` operator and multiplication operator `*` to perform the dot product between two matrices of differing sizes.
41
-
// Dot product, takes the row of the first matrix and multiplies it by the column of the second matrix, the `twoMatricesCheck` tested to see if they were the same size already.
42
-
// The dot product for each iteration is then saved to its respective index into `multMatrix`.
// Dot product, takes the row of the first matrix and multiplies it by the column of the second matrix, the `twoMatricesCheck` tested to see if they were the same size already.
42
+
// The dot product for each iteration is then saved to its respective index into `multMatrix`.
0 commit comments