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
62 lines (43 loc) · 1.33 KB
/
4-eligible-students.js
File metadata and controls
62 lines (43 loc) · 1.33 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
/*
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
*/
function eligibleStudents(arr){
let finalArray =[];
for(let i=0; i < arr.length; i++){
for(let j=0; j< arr[i].length; j++){
// console.log(arr[i][j]); //just to check output
if(arr[i][j] >= 8){
finalArray.push(arr[i][0]);
}
}
}
return finalArray;
}
//console.log(eligibleStudents(attendances));
/* ======= 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"]
);