Before writing any code you need to decide what steps the code should take to do the job.
Do you have a list of the steps the code needs to do?
For union?
For intersection?