Filter an array based on condition

 Problem

I have an array and want to filter its elements based on a defined condition.



 Recipe


// Initialize the Array
var a = [1,2,3,4,5,6]

// Get only even numbers: X % 2 = 0

a = a.filter { $0 % 2 == 0 }
print(a)
				


 Playground