mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
37 lines
630 B
JavaScript
37 lines
630 B
JavaScript
|
'use strict'
|
||
|
|
||
|
const ageGroup = {
|
||
|
BABY: 'B',
|
||
|
CHILD: 'K',
|
||
|
YOUNG: 'Y',
|
||
|
ADULT: 'E',
|
||
|
SENIOR: 'S',
|
||
|
upperBoundOf: {
|
||
|
BABY: 6,
|
||
|
CHILD: 15,
|
||
|
YOUNG: 27,
|
||
|
ADULT: 65,
|
||
|
SENIOR: Infinity
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const ageGroupFromAge = (age) => {
|
||
|
const {upperBoundOf} = ageGroup
|
||
|
if (age < upperBoundOf.BABY)
|
||
|
return ageGroup.BABY
|
||
|
if (age < upperBoundOf.CHILD)
|
||
|
return ageGroup.CHILD
|
||
|
if (age < upperBoundOf.YOUNG)
|
||
|
return ageGroup.YOUNG
|
||
|
if (age < upperBoundOf.ADULT)
|
||
|
return ageGroup.ADULT
|
||
|
if (age < upperBoundOf.SENIOR)
|
||
|
return ageGroup.SENIOR
|
||
|
throw new TypeError(`Invalid age '${age}'`)
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
ageGroup,
|
||
|
ageGroupFromAge
|
||
|
}
|