Jump to content
jo spanner

Simple array comparison?

Recommended Posts

Hey, I have a quick question:

Is there a way to check of all elements of an array are inside another array?

I can imagine a way of writing code for this, but I wonder if there is some built-in function that might be quicker?

 

Something to the effect of:

array1 = [1,2,3];
array2 = [5,1,6,2,7,3];

array1 in array2; //evaluates to true?

 

Share this post


Link to post
Share on other sites

Just messing around here. There are likely cases where this will not work, but it seems to work for simple arrays like this. I'm sure there is a much more elegant solution.

Code:

_a1 = [1,2,3];
_a2 = [1,2,3,4,5];

_compare = _a1 arrayIntersect _a2;
_bool = _compare isEqualTo _a1;

hint str _bool;

Result:
0.0092 ms

Cycles:
10000/10000

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×