Just playing around with algorithms in Javascript and Ruby