Home   Help Search Login Register  

Author Topic: Array Union, Intersect, and Except  (Read 836 times)

0 Members and 1 Guest are viewing this topic.

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Array Union, Intersect, and Except
« 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

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Array Union, Intersect, and Except
« Reply #1 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 :)

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:Array Union, Intersect, and Except
« Reply #2 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...

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Array Union, Intersect, and Except
« Reply #3 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

Offline benreeper

  • Members
  • *
  • I'm a llama!
Re:Array Union, Intersect, and Except
« Reply #4 on: 08 Oct 2005, 18:19:26 »
Isn't there  function for this?
--Ben

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Array Union, Intersect, and Except
« Reply #5 on: 08 Oct 2005, 19:23:34 »
i believe so but it isn't really necessary