In a bid to translate a little machine learning maths into javascript, I thought I'd start off by making a program that solves any nxn determinant via recursion. To break it down a little further it:
-
Takes an nxn array.
-
Performs a bunch of error checks to validate input.
-
If no errors are returned it passes the array into a function that performs the calculation.
-
Called using an error first callback
e.g
det( [[1,3],[2,4]], (err,res) => { if(err){ console.log(err) } else { console.log(res); //returns -2 } }); det( [[3,2,1],[2,-1,-3],[-1,2,-4]], (err,res) => { if(err){ console.log(err) } else { console.log(res); //returns 55 } });
Mindblowing stuff