A remove operation records deleting an item from the working array because it does not appear in the target array. Its index identifies where the item was removed. section 7.6.1
Implement removal as a small sequence of responsibilities:
- Check whether the current working-array item appears anywhere in the new array, using the configured equality function. section 7.6.4
- Create { op: 'remove', index, item }, then splice the item from both the working array and its original-index tracking array. section 7.6.4
- Keep the iteration index unchanged after removal, because the next working-array item shifts into the same position. section 7.6.2
- Remove every remaining working-array item after the new array has been fully processed. section 7.6.2
Removing items while diffing
For oldArray = [X, A, A, B, C] and newArray = [C, K, A, B], remove X at index 0 because it is absent from the target. After later moves and additions, remove the remaining extra A. The resulting remove records preserve each deletion's current index and item. section 7.6.3
[
{op: 'remove', index: 0, item: 'A'}
{op: 'move', originalIndex: 2, from: 1, index: 0, item: 'C'}
{op: 'noop', index: 1, originalIndex: 1, item: 'B'}
{op: 'add', index: 2, item: 'D'}
]
Inspect a complete operation sequence containing a removal alongside move, noop, and add operations. section 7.6.1
