Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 261 Bytes

AddDigitsSolutions.md

File metadata and controls

19 lines (17 loc) · 261 Bytes

Add Digits

Swift

func addDigits(of n: Int) -> Int {
    var n = n
    var sum = 0
    repeat {
        sum = 0
        while n > 0 {
            sum += n % 10
            n /= 10
        }
        n = sum
    } while sum > 9
    return sum
}