Python code for Waterbucket Problem converted to Javascript