Determinant of a matrix in JS

I’m currently reading Deep Learning, from Ian Goodfellow, Yoshua Bengio and Aaron Courville. While reading I got interested in calculating the determinant of a square matrix, I know there are many existing libraries to do that but the algorithm looked simply enough to give it a try.


Here’s my solution:

function det(m) { var size = Math.sqrt(m.length); if (size % 1 !== 0) { return null; } if (size === 2) { return m[0] * m[3] - m[1] * m[2]; } return m.slice(0, size).reduce(function(t, v, i)...
 •  0 comments  •  flag
Share on Twitter
Published on June 10, 2017 06:54
No comments have been added yet.