0

I have a couple functions like this:

object obj.getChild(childIndex)
int obj.numChildren()

So I am using these to create this function:

collection obj.getChildren()

I am flexible in the return type, but I will doing a lot of "subtraction", "multiplication" using another list. So something like this:

children = obj.getChildren()
children = [5,10,15,20,25]

globalChildren = [1,2,3,4,5,6,7,8,9,10,12,14,16,18,20]

difference = children - globalChildren
difference = [15,25]

shared = children * globalChildren
shared = [5,10,20]

Is there a fast and elegant way to do these or do I have to go through each element one by one and gather the elements manually?

1 Answer 1

3

You're looking for sets

children = {5,10,15,20,25}

globalChildren = {1,2,3,4,5,6,7,8,9,10,12,14,16,18,20}

difference = children - globalChildren
shared = children & globalChildren
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, can you please tell me what collection type are those {}?

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.