-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgeRangeCompatibilityEquation.js
More file actions
34 lines (24 loc) · 958 Bytes
/
AgeRangeCompatibilityEquation.js
File metadata and controls
34 lines (24 loc) · 958 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
/*
Instructions:
Everybody knows the classic "half your age plus seven" dating rule that a lot of people follow (including myself). It's the 'recommended' age range in which to date someone.
minimum age <= your age <= maximum age
Task
Given an integer (1 <= n <= 100) representing a person's age, return their minimum and maximum age range.
This equation doesn't work when the age <= 14, so use this equation instead:
min = age - 0.10 * age
max = age + 0.10 * age
You should floor all your answers so that an integer is given instead of a float (which doesn't represent age). Return your answer in the form [min]-[max]
##Examples:
age = 27 => 20-40
age = 5 => 4-5
age = 17 => 15-20
*/
function datingRange(age) {
return `${min(age)}-${max(age)}`;
function min(age) {
return Math.floor(age > 14 ? age / 2 + 7 : age - 0.1 * age);
}
function max(age) {
return Math.floor(age > 14 ? (age - 7) * 2 : age + 0.1 * age);
}
}