translate simple python functions to javascript