Task

Select certain elements from an Array into a new Array in a generic way.



To demonstrate, select all even numbers from an Array.

As an option, give a second solution which filters destructively,
by modifying the original Array rather than creating a new Array.




' write random nos between 1 and 100
' to array1 counting matches as we go
dim array1(100)
count=100
for i = 1 to 100
    array1(i) = int(rnd(0)*100)+1
    count=count-(array1(i) mod 2)
next
 
'dim the extract and fill it
dim array2(count)
for i = 1 to 100
    if not(array1(i) mod 2) then
        n=n+1
        array2(n)=array1(i)
    end if
next
 
for n=1 to count
    print array2(n)
next