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
68 lines (53 loc) · 1.63 KB
/
4-eligible-students.js
File metadata and controls
68 lines (53 loc) · 1.63 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
64
65
66
67
68
/*
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 filteredstudent = arr.filter(checkStudentAttendens);
function checkStudentAttendens(nameAndAttandens){
return nameAndAttandens[1] >=8;
}
console.log(filteredstudent);
let getStudentNames= filteredstudent.map(bringName);
function bringName(nameAndAttandens){
return nameAndAttandens[0];
}
console.log(getStudentNames)
return getStudentNames;
}
// function eligibleStudents(arr) {
// let newArr = [];
// for (let i = 0; i < arr.length; i++) {
// for (let j = 0; j < arr[i].length; j++) {
// if (arr[i][j] >= 8) {
// newArr.push(arr[i][0]);
// }
// }
// } return newArr;
// }
/* ======= 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"]
);