2

I'm attempting to de-dupe an enormous email list migration, however there's a catch. I'd like to take the duplicates and turn them into their own array (3rd).

Lets make these arrays very simple, and short.

a = ["[email protected]", "[email protected]"]
b = ["[email protected]"] 

Essentially i'm trying to make c = ["[email protected]"] because it's the only email that resides on both lists.

What I've attempted so far:

Is there an opposite to unqiq ?

ab = a + b
ab.uniq

returns: ["[email protected]", "[email protected]"]

Could I dump a + b into a third c array, and compare c to ab.uniq to get what's duplicated?

Am i missing an easier way to do this? Any help will be much appreciated!!!!

1 Answer 1

6

You want the intersection of the arrays.

c = a & b
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to turn a list with carriage returns into an array of strings? ["on]
Is the list a string, or an array? If it's a string, you can use String#split: "some string with carriage returns".split(/\r?\n/)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.