Translate Python to JavaScript