OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Doolittle on 04 Oct 2005, 07:26:53

Title: Array Union, Intersect, and Except
Post by: Doolittle on 04 Oct 2005, 07:26:53
I was wondering..is this the best way to get the result of values which appear in each array but not both???

a = [1, 2, 3, 4]
b = [1, 2, 3, 5]
c = (a - b) + (b - a)

..means c = [4, 5]

How to do this in OFP scripting?  Just like that, right...but is there an easier way?

Doolittle
Title: Re:Array Union, Intersect, and Except
Post by: Fragorl on 04 Oct 2005, 07:33:01
Hmmm.

I'm going to chance a 'yes, that's the best way' and a 'no, there is no better way', based on the fact that there are no specialised commands to do things like that to arrays, in the comref.

If you can find an algorithm to do what you want, then you're sorted anyhow :)
Title: Re:Array Union, Intersect, and Except
Post by: ACF on 04 Oct 2005, 22:48:27
Code: [Select]
{If (_x In _array1) Then {_array1 = _array1 - [_x]; _array2 = _array2 - [_x]}} ForEach _array2
_resultarray = _array1 + _array2
In English:
 If an element in _array2 is in _array1 then subtract that element from both.
 Add the leftovers together.

That's as slick as I can get it...
Title: Re:Array Union, Intersect, and Except
Post by: Triggerhappy on 04 Oct 2005, 23:10:28
...which is not the easy way to do it
stick to your original code doolittle, thats the best
Title: Re:Array Union, Intersect, and Except
Post by: benreeper on 08 Oct 2005, 18:19:26
Isn't there  function for this?
--Ben
Title: Re:Array Union, Intersect, and Except
Post by: Triggerhappy on 08 Oct 2005, 19:23:34
i believe so but it isn't really necessary