When the app is not changed, I have a list of numbers called originalArray. After making some modifications, I now have modifiedArray where some items were inserted or deleted from originalArray. I've written a function to identify all the items that were deleted or inserted from the originalArray.
var modifiedArray = [1,3,5,6,7,8,9,10,11];
var originalArray = [1,2,3,4,5,6];
var insertedArray = [];
var deletedArray = [];
function findChanges() {
for(var i = 0; i < originalArray.length; i++){
if(modifiedArray.indexOf(originalArray[i]) == -1){
deletedArray.push(originalArray[i]);
}
}
for(var i = 0; i < modifiedArray.length; i++){
if(originalArray.indexOf(modifiedArray[i]) == -1){
insertedArray.push(modifiedArray[i]);
}
}
}
Do you think this is the most efficient way to identify all the items that were deleted or inserted from the original array?
If you have any other suggestions, please let us know.
Thank you very much.