Page MenuHomeFeedback Tracker

New function BIS_fnc_getDeletedAndAdded
Closed, ResolvedPublic

Description

I'd like to propose a function i use pretty much in all interfaces with listboxes that need to be updated.
The purpose of this function is to know what have been added and deleted in an array.

Description: This function will parse reference and array to return added and deleted elements. The puspose of this function is to know what have been added and deleted in an array.
Syntax: [reference, array] call BIS_fnc_getDeletedAndAdded
Parameters: reference: Array - reference array

array: Array - updated array

Return Value: Array - in following format: [[deleted elements indexes], [added elements indexes]]

Details

Severity
None
Resolution
Open
Reproducibility
N/A
Operating System
Windows 11 x64
Operating System Version
23H2
Category
Scripting
Steps To Reproduce

Here is the code:

params ["_reference", "_array"];
private ["_toReturn"];

_toReturn = [[], []];
for [{ _i = 0 }, { _i < (count _reference) }, { _i = _i + 1 }] do {
	if((_array find (_reference select _i)) < 0) then {
		(_toReturn select 0) pushback _i; 
	};
};
for [{ _i = 0 }, { _i < (count _array) }, { _i = _i + 1 }] do {
	if((_reference find (_array select _i)) < 0) then {
		(_toReturn select 1) pushback _i; 
	};
};
_toReturn;

Event Timeline

XTankKiller updated the task description. (Show Details)Jun 17 2024, 4:55 AM
dedmen closed this task as Resolved.Jul 5 2024, 3:50 PM
dedmen claimed this task.
dedmen added a subscriber: dedmen.

The performance of your code is terrible.

params ["_oldArray", "_newArray"];

_added = _newArray - _oldArray;
_removed = _oldArray - _newArray;

Both your code and my code won't handle duplicate elements of which only one was removed.

We will not be adding this.

This comment was removed by Geez.
Geez added a subscriber: Geez.Jul 11 2024, 10:59 AM