Made the ALGORITHM function work properly. Unfortunately, the approach that improved speed 10x in C++ is making it slightly slower in JS.
Will have to work on some profiling to see which equations are adding the overhead.
ALGORITHM function is still rough around the edges, so that's probably it.

Signed-off-by: alecmilne <milne_alec@hotmail.com>