Keeping the while loop is fine but as much as possible we should use lodash / underscore . It is easier to read and easier to deal with coffeescript to js.