Code is similar to below:
type Contact struct {
Id string
Email string
}
type EmailDifference struct {
Id string
OldEmail string
NewEmail string
}
func main() {
ContactList1 := []Contact{
Contact{
Id: "A01",
Email: "email1@mail.com",
},
Contact{
Id: "A02",
Email: "secondemail@mail.com",
},
Contact{
Id: "C00",
Email: "someemail@mail.com",
},
}
ContactList2 := []Contact{
Contact{
Id: "A01",
Email: "email23441@mail.com",
},
Contact{
Id: "A02",
Email: "2ndmail@mail.com",
},
Contact{
Id: "C00",
Email: "someemail@mail.com",
},
}
//How to find contacts with same ID but different emails from the above 2 contact lists?
}
I need to output a slice []EmailDifference{} containing contacts with same ID but different emails. How to do it efficiently, without using 2 for loops (i.e. comparing each element of ContactList1 with all elements of ContactList2 until a match in ID is found, then note that result if 2 emails are different)?