Some practice work on writing algorithms in JavaScript