Maxmaxmaximus4,
лови, теперь с блэкджеком и replace
Array.prototype.compare = function(arr) {
var search = arr.slice(),
insert = [],
remove = [],
replace = [];
for(var i = 0, index; i < this.length; i++) {
index = search.indexOf(this[i]);
if(!~index) {
remove.push(i);
continue;
}
i != index && replace.push({old: i, new: index});
delete search[index];
};
search.forEach(function (elem, i) {
if(elem)
insert.push(i);
});
return {
remove: remove,
insert: insert,
replace: replace
}
}
console.log([1, 2, 3, 4, 5].compare([1, 2, 3, 5, 4, 45]));