KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to remove duplicated elements from an array
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: February 8, 2013

The utility method below will remove any duplicated elements from an array.

C_POINTER($1;$arrPtr)
C_INTEGER($arrSize;$i)

$arrPtr:=$1
$arrSize:=Size of array($arrPtr->)

$i:=1
While ($i<$arrSize)
   $element:=Find in array($arrPtr->;$arrPtr->{$i};$i+1)
   If ($element#-1)
      DELETE FROM ARRAY($arrPtr->;$element)
      $arrSize:=$arrSize-1
      $i:=$i - 1
   End if
   $i:=$i + 1
End while


The method (named trim in this example) takes a pointer to an array. The following is an example of the method being used:

trim(->$temp)