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
49 lines (39 loc) · 1.29 KB
/
4-eligible-students.js
File metadata and controls
49 lines (39 loc) · 1.29 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
/*
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 who have attended AT LEAST 8 classes
*/
//nested array [0] name [1] attendance, return array with just index [0] if [1] is >= 8
function eligibleStudents(attendancesArray) {
let namesArray = [];
for(let i= 0; i < attendancesArray.length; i++) {
if (attendancesArray[i][1] >= 8) {
namesArray.push(attendancesArray[i][0]);
}
} return namesArray;
};
/* ======= 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"]
);