Stack manipulation practice in JavaScript and Python