let a =[[1,2],
[3,4]];
let b =[[5,6],
[7,8]];
let r =[[19,22]
[43,50]];
function add (a, i) {
let b = this[i];
return a.map ((a, j) => a + b[j]);
}
function sub (a, i) {
let b = this[i];
return a.map ((a, j) => a - b[j]);
}
function mult (a) {
let b = this;
return b[0].map ((_,j)=> a.reduce ((d,e,f)=> d + e * b[f][j], 0));
}
function transpose (_, i, b) {
return b.map ((_, j)=> b[j][i])
}
let d = a.map (mult, b);
console.log (d);
class Matrix {
static add (a, b) { return a.map((a,i)=> b[i].map((b,j)=> a[j]+b)) }
static sub (a, b) { return a.map((a,i)=> b[i].map((b,j)=> a[j]-b)) }
static mult (a, b) { return a.map(a=> a.map((_, i)=> b.reduce((g,_,j)=> g + a[j]*b[j][i],0))) }
static transpose (a) { return a[0].map((_,i)=> a.map ((_,j)=> a[j][i]))}
}