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.




dim a1(100)
count	= 100
for i = 1 to 100
    a1(i) = int(rnd(0)*100)+1
    count = count - (a1(i) mod 2)
next
 
'dim the extract and fill it
dim a2(count)
for i = 1 to 100
    if not(a1(i) mod 2) then
        n	= n+1
        a2(n)	= a1(i)
    end if
next
 
for i = 1 to count
    print a2(i)
next