Last active
December 10, 2018 02:20
-
-
Save pawelkijowskizimperium/b8ed6ae939f554ef8c88a9e99ed1c70c to your computer and use it in GitHub Desktop.
Efficient digital root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
func digitalRoot(of number: Int) -> Int { | |
if (number <= 0) { | |
return number | |
} else if (number % 9 == 0) { | |
return 9 | |
} else { | |
return number % 9 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment