I don't like this so much, it looks like we might slicing/concatenating the same part of the strings multiple times.

I'd rather build a result string with parts of the initial input text. Also, I know that gecko is quite smart with string concatenation (ie: it doesn't concatenate it for real) until we try to read it entirely... which we do at each step here.

How about this instead:

```javascript
var result = '';
var oldEnd = -1;

linkSpecs.forEach(function replaceLink(link) {
  result += inputText.slice(oldEnd + 1, link.start);

  var replacing = inputText.slice(link.start, link.end);
  var replaceWith = LINK_TYPES[link.type].transform(replacing, link);
  result += replaceWith;
  oldEnd = link.end;
});

result += inputText.slice(oldEnd + 1);
```

result is never read before the end, and we only slice unique part of inputText.