Skip to content

Instantly share code, notes, and snippets.

@TheDarkCode
Created May 13, 2019 07:33
Show Gist options
  • Save TheDarkCode/b84a026b71dc9abad63e76800e7e9ab7 to your computer and use it in GitHub Desktop.
Save TheDarkCode/b84a026b71dc9abad63e76800e7e9ab7 to your computer and use it in GitHub Desktop.
Swift Numerology - Date Numerology Example
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