an iterative coffeescript solution