This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy path1-oxygen-levels.js
More file actions
63 lines (47 loc) · 1.61 KB
/
1-oxygen-levels.js
File metadata and controls
63 lines (47 loc) · 1.61 KB
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
/*
Many years into the future, a team of Space Voyagers find their ship is low on Oxygen and need to dock
somewhere safe while they call home for help.
Their computer detects a list of nearby planets that have Oxygen in their atmosphere. It has produced an array of their Oxygen levels.
To be safe to land on, a planet needs to have an Oxygen level between 19.5% and 23.5%.
Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5%
*/
function findRightPlanet (oxygenLevelOfPlanet) {
if (parseFloat(oxygenLevelOfPlanet) > 19.50 && parseFloat(oxygenLevelOfPlanet) < 23.50) {
return `${oxygenLevelOfPlanet}%`;
}
else {
return;
}
}
function safeLevels(oxygenLevel) {
return oxygenLevel.find(findRightPlanet);
}
/* ======= TESTS - DO NOT MODIFY ===== */
const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"];
const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"];
const oxygenLevels3 = ["200%", "21.1%"];
const util = require('util');
function test(test_name, actual, expected) {
let status;
if (actual === expected) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}
console.log(`${test_name}: ${status}`);
}
test(
"safeLevels function works - case 1",
safeLevels(oxygenLevels1),
"19.9%"
);
test(
"safeLevels function works - case 2",
safeLevels(oxygenLevels2),
"20.2%"
);
test(
"safeLevels function works - case 3",
safeLevels(oxygenLevels3),
"21.1%"
);