Skip to content

Instantly share code, notes, and snippets.

@mkock
Created August 20, 2020 19:28
Show Gist options
  • Select an option

  • Save mkock/e4f56aaf6bdb77d8048fbba5d93e0cc9 to your computer and use it in GitHub Desktop.

Select an option

Save mkock/e4f56aaf6bdb77d8048fbba5d93e0cc9 to your computer and use it in GitHub Desktop.
Bus Ride, code snippet 28
// SeniorAge is the minimum age from which a Passenger is considered a senior to the BusCompany.
const SeniorAge = 65
// IsSenior returns true if the Passenger is a senior, and false otherwise.
// IsSenior detects age by extracting the last two digits from the SSN and treating them like an age.
func (p Passenger) IsSenior() bool {
age,err:=strconv.ParseInt(p.SSN[len(p.SSN)-2:],10,8)
if err != nil {
panic("invalid SSN: " + p.SSN)
}
return age >= SeniorAge
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment