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 path4-eligible-students.js
More file actions
51 lines (43 loc) · 1.22 KB
/
4-eligible-students.js
File metadata and controls
51 lines (43 loc) · 1.22 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
/*
Only students who have attended enough classes are eligible to sit an exam.
Create a function which:
- Accepts an array which contains all the students' names and their attendance counts
(see tests to confirm how this data will be structured)
- Returns an array containing only the names of the students who have attended AT LEAST 8 classes
*/
function eligibleStudents(studentWork) {
let studentsWhoCanSitExam = [];
for (i = 0; i < studentWork.length; i++) {
if (studentWork[i][1] >= 8) {
studentsWhoCanSitExam.push(studentWork[i][0]);
}
}
return studentsWhoCanSitExam;
}
/* ======= TESTS - DO NOT MODIFY ===== */
const attendances = [
["Ahmed", 8],
["Clement", 10],
["Elamin", 6],
["Adam", 7],
["Tayoa", 11],
["Nina", 10],
];
const util = require("util");
function test(test_name, actual, expected) {
let status;
if (util.isDeepStrictEqual(actual, expected)) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(
expected
)} but your function returned: ${util.inspect(actual)}`;
}
console.log(`${test_name}: ${status}`);
}
test("eligibleStudents function works", eligibleStudents(attendances), [
"Ahmed",
"Clement",
"Tayoa",
"Nina",
]);