Algorithm practice using JavaScript and Python