code: function sortSegmentRow(segments) {
  		var sortedSegments = [];
  
  		// build the subrow array
  		var subrows = buildSegmentSubrows(segments);
  
  		// flatten it
  		for (var i=0; i<subrows.length; i++) {
  			sortedSegments.push.apply(sortedSegments, subrows[i]); // append an array to an array
  		}
  
  		return sortedSegments;
  	}
docs: Sort an array of segments according to which segment should appear closest to the top