using javascript to solve some sample algorithms questions