Trying out different algorithms in javascript