This algorithm only works, I think if you know that the indexes are listed in the same order, or if you call sort() on them here.

In any case, given that there will always be a small number of indexes, I think it would be much simpler to just use an O(n*n) algorithm:

1) Loop through the new list of indexes. For each one, if it does not exist (using Array.indexOf) in the old list of indexes, then create it.

2) Loop through the old list of indexes. For each one, if it does not exist in the new list of indexes, then delete it.