-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathageGroup.js
More file actions
39 lines (37 loc) · 644 Bytes
/
ageGroup.js
File metadata and controls
39 lines (37 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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}'`);
};
export {
ageGroup,
ageGroupFromAge,
};