Converting Python to JS