Created
June 19, 2018 13:19
-
-
Save e-mihaylin/4a467b500b76a540cebb9875a32c9d6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const determinant = m => { | |
const l = m.length; | |
if (l === 1) return m[0][0]; | |
if (l === 2) return m[0][0] * m[1][1] - m[1][0] * m[0][1]; | |
let result = 0; | |
for (let i = 0; i < l; i++) { | |
result += Math.pow(-1, i) * m[0][i] * determinant(minor(m, i, 0)); | |
} | |
return result; | |
}; | |
const minor = (m, i, j) => | |
m.map(e => e.filter((_, index) => index !== i)) | |
.filter((_, index) => index !== j); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment