D
D
DanSama2021-05-25 09:34:50
Arrays
DanSama, 2021-05-25 09:34:50

How to iterate over two arrays and exclude duplicates from them, taking into account that duplicates can be located asynchronously?

Can you please tell me how to iterate over two arrays and exclude duplicates from them, taking into account that duplicates can be located asynchronously?
Example
There are 2 arrays (numbers are arbitrary)
let a = [1, 2, 3,4,5, -1,9]
let b - [3,4, -1,5,6,7]
After iteration, return array a without the elements that are in the array b. The array b does not need to be changed.
t.s. Array a should be = [1,2,9]
Array b unchanged
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-05-25
@wataru

You can sort both arrays and then walk through them with two pointers in parallel, as in a merge.
Or add a second array to some hash table and then iterate over the first array to see if the current element is in the table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question