Converting some ruby methods into Javascript functions.