I have the following C# code which solves the problem using the Except() function:
List<String> origItems = new List<String>();
origItems.Add("abc");
origItems.Add("def");
origItems.Add("ghi");
List<String> newItems = new List<String>();
newItems.Add("abc");
newItems.Add("def");
newItems.Add("super");
newItems.Add("extra");
List<String> itemsOnlyInNew = newItems.Except(origItems).ToList();
foreach (String s in itemsOnlyInNew){
Console.WriteLine(s);
}
The output for this will be:
super
extra
The result is the two items from the 2nd list which are not contained in the 1st list.
Using Modern JavaScript
If I have two arrays in JavaScript
let origItems = ['abc','def','ghi'];
let newItems = ['abc','def','super','extra'];
What would be the most efficient & clearest way to solve this problem?
Is there a method simlar to C# Except?
Or is it necessary to iterate over every item in the first array for each item in the 2nd array?
Additional Constraint for Understanding the Problem
The original arrays are not necessarily pre-sorted and each can be in any order. They just happen to be that way in the data. That means if part of your solution is that they are sorted then it must show that in the answer.