arrayIntersect: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) No edit summary |
Hypoxic125 (talk | contribs) No edit summary |
||
Line 44: | Line 44: | ||
|seealso= [[append]] [[set]] [[pushBack]] [[pushBackUnique]] [[apply]] [[select]] [[resize]] [[reverse]] [[count]] [[find]] [[in]] [[forEach]] [[deleteAt]] [[deleteRange]] [[sort]] [[param]] [[params]] [[toArray]] [[toString]] [[splitString]] [[joinString]] [[BIS_fnc_arrayPushStack]] [[BIS_fnc_arrayPush]] | |seealso= [[append]] [[set]] [[pushBack]] [[pushBackUnique]] [[apply]] [[select]] [[resize]] [[reverse]] [[count]] [[find]] [[in]] [[forEach]] [[deleteAt]] [[deleteRange]] [[sort]] [[param]] [[params]] [[toArray]] [[toString]] [[splitString]] [[joinString]] [[BIS_fnc_arrayPushStack]] [[BIS_fnc_arrayPush]] | ||
}} | |||
{{Note | |||
|user= Hypoxic125 | |||
|timestamp= 20240526165002 | |||
|text= Selectively filter out elements from _arrayA based on _arrayB. | |||
* Designed to remove the first occurrence of each element found in _arrayB from _arrayA. | |||
* Useful in removing elements where duplicates may exist. | |||
<sqf> | |||
private _arrayA = [1,2,3,2,4,5,4]; | |||
private _arrayB = [2,2,4]; | |||
{ | |||
private _element = _x; | |||
private _index = _arrayA find _element; | |||
if (_index != -1) then { | |||
_arrayA deleteAt _index; | |||
}; | |||
} forEachReversed _arrayB | |||
_arrayA | |||
// Returns [1,3,5,4] | |||
</sqf> | |||
}} | }} |
Revision as of 17:50, 26 May 2024
Description
- Description:
- Intersects two arrays returning an array of unique common elements, avoiding nil values. Using the same array as both parameters will return unique elements of that array. Intersects only the first dimension of said arrays.
- Groups:
- Arrays
Syntax
- Syntax:
- array1 arrayIntersect array2
- Parameters:
- array1: Array
- array2: Array
- Return Value:
- Array
Examples
- Example 1:
- Example 2:
- Example 3:
- Remove nils:
- Example 4:
- Also works with array elements which are equal:
- Example 5:
- This command is case-sensitive:
["cAse"] arrayIntersect ["cAse"]; // ["cAse"] ["cAse"] arrayIntersect ["casE"]; // []
Additional Information
- See also:
- append set pushBack pushBackUnique apply select resize reverse count find in forEach deleteAt deleteRange sort param params toArray toString splitString joinString BIS_fnc_arrayPushStack BIS_fnc_arrayPush
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on May 26, 2024 - 16:50 (UTC)
-
Selectively filter out elements from _arrayA based on _arrayB.
- Designed to remove the first occurrence of each element found in _arrayB from _arrayA.
- Useful in removing elements where duplicates may exist.