Is it possible to compare arrays based on the changes in their element positions?
I have an original array of objects that has one of its elements' values changed, resulting in a new array:
origElements = [{id: 1, value: 50},
{id: 2, value: 60},
{id: 3, value: 70}]
changedElements = [{id: 1, value: 50},
{id: 3, value: 60},
{id: 2, value: 120}]
var diff = _.difference(_.pluck(origElements, "id"), _.pluck(changedElements, "id"));
var result = _.filter(origElements, function(obj) { return diff.indexOf(obj.id) >= 0; });
In this scenario, 'result' would not yield any results because there are no differences in values between the arrays [1, 2, 3] and [1, 3, 2]. I am looking to implement a 'strict difference' that considers the index as well, providing information on the new order of the objects.