0 votes

Is there way to check what my arrays has for example:
if arrays has [2,2,3] or [3,3,3]:
do something;

Godot version latest
in Engine by (39 points)

1 Answer

0 votes
Best answer

Create your own function as:

func has_all(your_elements:Array, your_array:Array):
    for element in your_elements:
        if not your_array.has(element):
            return false
    return true
by (1,049 points)
selected by

Example usage:

if has_all([1,2,3],[1,2,3,4,5,6,7]):
    print("All elements in array 1 are in array 2.")

Thank you so much! It works.

I tested something. it just check that if 1 and 2 are in the array it is true, but it doesn't care about the the duplicates like [1,3,3] = false but [1,1,3] == true or [3,1,1] == true or [1,3,1] == true

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.