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.




# Built-in
 
Filtered([1 .. 100], IsPrime);
# [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ]
 
Filtered([1 .. 10], IsEvenInt);
# [ 2, 4, 6, 8, 10 ]
 
Filtered([1 .. 10], IsOddInt);
# [ 1, 3, 5, 7, 9 ]