Created
May 13, 2019 07:33
-
-
Save TheDarkCode/b84a026b71dc9abad63e76800e7e9ab7 to your computer and use it in GitHub Desktop.
Swift Numerology - Date Numerology Example
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
public extension Int { | |
var digits: [Int] { | |
return String(self).compactMap{ Int(String($0)) } | |
} | |
var reduction: Int { | |
return self.digits.reduce(0,+) | |
} | |
} | |
public extension Date { | |
var dayMonthYear: (Int, Int, Int) { | |
let components = Calendar.current.dateComponents([.day, .month, .year], from: self as Date) | |
return (components.day!, components.month!, components.year!) | |
} | |
func FullNumerology() -> Int { | |
let components = self.dayMonthYear | |
return components.0.reduction + components.1.reduction + components.2.reduction | |
} | |
} | |
// Usage: print(Date().FullNumerology()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment