Created
August 20, 2020 19:28
-
-
Save mkock/e4f56aaf6bdb77d8048fbba5d93e0cc9 to your computer and use it in GitHub Desktop.
Bus Ride, code snippet 28
This file contains hidden or 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
| // 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