Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shared Method to Arrays #2331

Closed
mrjustaguy opened this issue Feb 22, 2021 · 1 comment
Closed

Add Shared Method to Arrays #2331

mrjustaguy opened this issue Feb 22, 2021 · 1 comment

Comments

@mrjustaguy
Copy link

Describe the project you are working on

Various

Describe the problem or limitation you are having in your project

There are multiple instances where knowing if 2 arrays have any shared data would could be useful

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding a Shared() method to Arrays would allow for very simple, single line checks if there is any identical data between 2 arrays.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Array1=[0,1,2]
Array2=[0,4,5,6,7]
Array1.Shared(Array2) -> returns true

Array1=[0,1,2]
Array2=[3,4]
Array1.Shared(Array2) -> returns false

Implementation:
for i in range elements in array 1 iterate for j in range elements in array 2, if element i of array 1 == element j of array 2 return true, if iterations end and it didn't return true, return false

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, one can make a function to do that that would take 6 lines of GDScript code (func, 2 for loops, if, 2 returns)

Is there a reason why this should be core and not an add-on in the asset library?

Array is core

@KoBeWi
Copy link
Member

KoBeWi commented Feb 22, 2021

This is called intersection.
Duplicate of #1756

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants