0

I'm trying to make a sort of Venn Diagram and I have an array of arrays that stores the data that is in each unique set. So something like:

array[0] = [1, 2, 3, 4]
array[1] = [2, 3, 4, 5]
array[2] = [3, 4, 6, 10, 15, 20]
array[3] = [15, 20, 25]

There could be up to 10 arrays within this original array set.

What I'm trying to do is to find similarities between sets but also have the ability to get the exclude sets. For example, if I want to find the similarities between the first and second array in the example above but exclude the third array, I would end up getting: [2] but not [3, 4] since it is not in the third set. I would want all possibilities to be available: selecting as many arrays and excluding as many arrays.

Is there an easy way of doing this? I was thinking in the lines of jquery with classes. Attaching each entry of the array and excluding everything was asked to be excluded. But I don't know if that's the correct way of going about it. Would I have to read each content of each array and combine them?

1 Answer 1

1

Look at the underscore.js library which allows you to do set manipulation like:

_.difference([1, 2, 3, 4, 5], [5, 2, 10]);
=> [1, 3, 4]

and

_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
=> [1, 2]
Sign up to request clarification or add additional context in comments.

2 Comments

This seems useful! I'm curious on how fast it would be because there's a lot of permutations on 10 sets and I need to sort the results as a heatmap from the most common occurrence to the least common occurrence. Any advice on how to do that manually would be really great as well! Would a double for loop be the only thing to do?
We don't do your homework. You'll need to try something and if necessary, create a new question.

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.