Get rid of O(n^2) string-concat.

See e.g. http://stackoverflow.com/questions/2781686/javascript-string-concatenation-slow-performance-array-join
Merge pull request #1 from kousu/master

Get rid of O(n^2) string-concat.