Swift - Write program to return the number of digits divisible by 3

Requirements

Write program to return the number of digits divisible by 3

Also count the even and odd numbers

Return the three value together from the function

Demo

func count(string: String) -> (odd:Int, even:Int, threes:Int ) {
        var odd = 0, even = 0, threes = 0
        for char in string {
            let digit = String(char).toInt()
            if (digit != nil) {
                (digit!) % 2 == 0 ? even++ : odd++
                  (digit!) % 3 == 0 ? threes++ : 0
            }// w  ww  .  j  a  va 2s  . c  om
        }
        return  (odd, even,  threes )
    }

var result = count ("123456789")
print("Odd: \(result.odd)")         //5
print("Even: \(result.even)")       //4
print("Threes: \(result.threes)")   //3

Related Exercise