Module: module

Methods

(static) calculateAge(p) → {number}

Calculate a person's age in years. This function verifies that the parameter is valid, checks the birth date format, and then calculates the age based on the current date. The function is intentionally written in a clear and step-by-step way (student style) to make validation logic easy to understand and test.
Parameters:
Name Type Description
p Object Object representing a person
Properties
Name Type Description
birth Date Birth date of the person
Source:
Throws:
If: - parameter is missing - parameter is not an object - birth field is missing - birth is not a Date - birth date is invalid
Type
Error
Returns:
Age in years
Type
number