The code example in the Lists section of the reference docs is misleading. The example transformations presented do not reflect what's written in the comments.
The code vs. comment discrepancy starts in this line
Which splices the list at idx 2 removing 2 elements:
// now doc.list is [0, 2, 4, 6.283185307179586]
doc.list.splice(2, 2, "automerge");
// now doc.list is [0, 'hello', 'automerge', 4]
It's impossible to arrive at the result list just by using splice.
Running the same sequence (truncated above) in my browser console gives me a very different list
>> Automerge.change(Automerge.init(), (d) => { d.list = []; d.list.push(2,3); d.list.unshift(0,1); d.list[3] = Math.PI; for (let i =0; i<d.list.length; i++) {d.list[i]*= 2} ; d.list.splice(2,2,"automerge") ; }).list
> Array(3) [ 0, 2, "automerge" ]
Subsequent lines make a bunch of further modifications, which are not self-explanatory, and we end up with
I tried rewriting this section locally to make a PR, but I'm not quite sure how to get from-here-to-there, i.e which operations (or comments) to re-write. So instead I'm just flagging this as a exposition/clarity bug in the docs.