Here is the blog post explaining details of the approach.
You can find the demo here.
I used math.js library to perform matlab-like matrix operations but I suspect that was an overkill. All the indexing and range operators didn't make life easier.
This repository also contains a MATLAB implementation.