-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjs-1.js
83 lines (48 loc) · 2.12 KB
/
js-1.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
JavaScript exercises. Please fill in solutions as below.
NOTE: do *not* rename the functions provided, as the auto-grader expects them to be named as defined.
*/
/*
Problem 1 - BMI
concept: if statements
Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. It's a simple calculation:
<img src="https://www.gstatic.com/education/formulas/images_long_sheet/en/body_mass_index.svg" alt="\text{BMI}=\frac{m} {{h}^2}"/>
In plain text, BMI = ( m / h^2 ). BMI is a simple number, for example, Charles has 187cm tall, and weighs 85 kg, which equals BMI of 24.3.
From Wikipedia, the commonly accepted BMI ranges are underweight (< 18.5), normal weight ( >= 18.5 and < 25), overweight (>=25 and < 30), and obese (>=30).
Write a simple function that takes in two arguments - height (in cm), weight (in kg), and returns either "underweight", "normal", or "overweight", or "obese" as a plain string.
Examples:
bmi(188, 85) --> normal
bmi(150, 35) --> underweight
*/
function bmi(height, weight) {
// Your code here
return "normal";
}
/* Problem 2 - How many normal people?
From the previous question, we know 25-30 is a "normal" BMI. Write a function that returns how many "normal" people are in a provided array of numbers.
Examples:
countNormal([24,25,22,30.1,18]) --> 2
countNormal([18.5, 31]) --> 1
countNormal([]) --> 0
*/
function countNormal(arr) {
// Your code here
return 0;
}
/*
Problem 3 - How many of each type?
This builds upon the previous question. Instead of only returning the number of normal people, return an object returning the count for each body type. The keys should be "underweight, normal, overweight, obese".
If there are no people of a category, set the value to 0.
Examples:
countTypes([20,24,30,31.1,18]) --> { underweight: 1, normal: 2, overweight: 1, obese: 1 }
countTypes([20,24]) --> { underweight: 0, normal: 2, overweight: 0, obese: 0 }
*/
function countTypes(obj) {
return {};
}
// DO NOT TOUCH CODE BELOW OR YOU WILL FAIL (i think)
module.exports = {
bmi,
countNormal,
countTypes
}