Matrix dot product

To calculate matrix dot product (and to decently display it in the browser), you don't need anything but a few lines of code that fits into single page (HTML + CSS + JS). No external dependencies.

<style> main { display: flex; align-items: center; } .matrix { margin: 0 1em; border-left: 1px solid black; border-right: 1px solid black; } .matrix b { display: inline-block; width: 2em; text-align: center; } </style> <main> <div class="matrix" id="A">[[1, 2], [2, 3], [3, 4]]</div> &centerdot; <div class="matrix" id="B">[[3, 2, 1], [4, 3, 2]]</div> = <div class="matrix" id="C"></div> </main> <script> let Matrix = (M, fromSelf) => M.innerHTML = (fromSelf ? (M.value=eval(M.innerHTML)) : M.value).map(r => r.map(c => `<b>${c}</b>`).join('')).join('<br>') let MatrixProd = (A, B) => A.map((row, i) => B[0].map((_, j) => row.reduce((acc, _, n) => acc + A[i][n] * B[n][j], 0 ) ) ) Matrix(A, true) Matrix(B, true) C.value = MatrixProd(A.value, B.value) Matrix(C) </script>