global proc int[] removeDuplicateIntegers(int $array[])
{
int $index = 0;
int $newarray[];
for( $i = 0 ; $i < size($array) ; $i++ )
{
$entry = true;
for( $j = 0 ; $j < $i ; $j++ )
{
if( $array[$i] == $array[$j] ) //duplicate
$entry = false;
}
if( $entry == true )
{
$newarray[$index] = $array[$i];
$index++;
}
}
return $newarray;
}
global proc float[] removeDuplicateFloats(float $array[])
{
int $index = 0;
float $newarray[];
for( $i = 0 ; $i < size($array) ; $i++ )
{
$entry = true;
for( $j = 0 ; $j < $i ; $j++ )
{
if( $array[$i] == $array[$j] ) //duplicate
$entry = false;
}
if( $entry == true )
{
$newarray[$index] = $array[$i];
$index++;
}
}
return $newarray;
}
int $arrayi[] = {0,1,1,0,2,4,1,6};
float $arrayf[] = {0.0,0.1,0.1,0.0,0.2,0.4,0.1,0.6};
print(removeDuplicateIntegers($arrayi));
print(removeDuplicateFloats($arrayf));
This loops through the array and matches the entry with all previous entries with a double for loop. If an entry is the same as any previous it does not get entered into the output array. Be aware though that entering the new array straight into the old array variable it is very well possible that the old array is longer than the new one, any entries that are beyond the new array are then not replaced with blank fields resulting in the function defying its purpose and the creation of new duplicate entries.