I state that I have tried for a long time before writing this post.
For an InDesign script, I\'m working with two array of ListItems. Now I\'m trying to remove the items
You can make use of Array.prototype.filter and Array.prototype.concat to simply it:
arr_A = ["a","b","d","f","g"]
arr_B = ["a","g","k"]
arr_C = ["h"]
function getCommonItems(arrayA, arrayB, result) {
result = result || [];
result = result.concat(arrayA.filter(function(item) {
return arrayB.indexOf(item) >= 0;
}));
return result.sort();
}
alert(getCommonItems(arr_A, arr_B, arr_C).join(", "));
alert(getCommonItems(arr_B, arr_A, arr_C).join(", "));
For the first scenario:
arr_A = ["a","b","d","f","g"]
arr_B = ["a","c","f","h"]
function getDifference(arrayA, arrayB, result) {
return arrayB.filter(function(item) {
return arrayA.indexOf(item) === -1;
}).sort();
}
alert(getDifference(arr_A, arr_B).join(", "));
alert(getDifference(arr_B, arr_A).join(", "));