Created
December 11, 2020 03:54
-
-
Save DeVoresyah/97a0309d41c574a2273768cb6a5a12af to your computer and use it in GitHub Desktop.
Find Suitable Sport
This file contains 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
const sports = [{ | |
id: "Basketball", | |
age: { | |
min: 18, | |
max: 30 | |
}, | |
males: { | |
min: 40, | |
max: 60 | |
}, | |
females: { | |
min: 43, | |
max: 60 | |
} | |
}, { | |
id: "Bicycling", | |
age: { | |
min: 18, | |
max: 26 | |
}, | |
males: { | |
min: 62, | |
max: 74 | |
}, | |
females: { | |
min: 47, | |
max: 57 | |
} | |
}, { | |
id: "Canoeing", | |
age: { | |
min: 18, | |
max: 26 | |
}, | |
males: { | |
min: 55, | |
max: 67 | |
}, | |
females: { | |
min: 47, | |
max: 67 | |
} | |
}, { | |
id: "Gymnastics", | |
age: { | |
min: 18, | |
max: 22 | |
}, | |
males: { | |
min: 52, | |
max: 58 | |
}, | |
females: { | |
min: 36, | |
max: 50 | |
} | |
}, { | |
id: "Swimming", | |
age: { | |
min: 10, | |
max: 25 | |
}, | |
males: { | |
min: 50, | |
max: 75 | |
}, | |
females: { | |
min: 40, | |
max: 60 | |
} | |
}] | |
const findSport = (HRrest, age, gender) => { | |
const getAge = Number(age) | |
if (getAge < 0 || HRrest < 0) { | |
return "Error: Value must not be negative." | |
} else { | |
const HRMax = 220 - getAge | |
const VO2Max = 15 * (HRMax / HRrest) | |
const getGender = gender.toLowerCase() | |
return sports.find(item => ( | |
getAge >= item.age.min && getAge <= item.age.max | |
) && getGender === "male" || getGender === "m" ? ( | |
VO2Max >= item.males.min && VO2Max <= item.males.max | |
) : ( | |
VO2Max >= item.females.min && VO2Max <= item.females.max | |
)).id | |
} | |
} | |
findSport(50, 20, "m") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment