Твоя функция не справилась с этим
var oldArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var newArray = [1, 2, 3, 5, 34, 32, 4, 45];
var changes = compare(oldArray, newArray);
console.log(changes);
function compare(oArr, arr) {
var search = arr.slice();
var insert = [];
var remove = [];
for (var i = 0, index; i < oArr.length; i++) {
index = search.indexOf(oArr[i]);
if (index < 0) remove.push(i);
else delete search[index];
}
for (var i = 0; i < search.length; i++) {
if (i in search) insert.push(i);
}
return {
remove: remove,
insert: insert
}
}