How to check what elements my arrays has?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sugor

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

:bust_in_silhouette: Reply From: magicalogic

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

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.")

magicalogic | 2021-05-16 12:02

Thank you so much! It works.

Sugor | 2021-05-16 12:04

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

Sugor | 2021-05-16 12:07