How do I remove the oldItems from the newItems string? (remove Blue and Green) newItems is generated from jQuery autocomplete and I would like to remove already selected items from the select list.
newItems = Blue \n Red \n Black \n Yellow \n Green \n
oldItems = Blue,Yellow,Orange,Green
Best regards.
Asbjørn Morell.
One algorithm would be to look at each of the oldItems and search for them in the newItems array. However, if you expect these arrays to reach any length, this is going to be
O(n^2). This is essentially the algorithm given by Jacob Relkin.However, instead, if you sort the two lists, you can do it faster.
This walks through the two lists looking for duplicates in the new list in the old list. This should be O(n log n) because of the two sort operations.