JavaScript version of the watershed concatenation.