Swift - Write program to extract only the odd numbers from the array

Requirements

Write program to extract only the odd numbers from the array

Demo

var numbers = [5,6,3,2,4,8,1,0]

var oddNumbers = numbers.filter (
    {//from ww w .j a v a 2  s  . co m
         (num: Int) -> Bool in
            num % 2 == 1
    }
)
print(oddNumbers)//[5, 3, 1]

Result

Related Exercise