-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_deep_foundations_function_scope_arrow_resolved.js
65 lines (56 loc) · 1.67 KB
/
04_deep_foundations_function_scope_arrow_resolved.js
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
var getStudentFromId = studentId => studentRecords.find(record => record.id == studentId);
var printRecords = recordIds =>
recordIds.map(getStudentFromId)
.sort(
(record1,record2) => record1.name < record2.name ? -1 : record1.name > record2.name ? 1 : 0
)
.forEach(record =>
console.log(`${record.name} (${record.id}): ${record.paid ? "Paid" : "Not Paid"}`)
);
var paidStudentsToEnroll = () =>
[ ...currentEnrollment,
...(
studentRecords.filter(record => (record.paid && !currentEnrollment.includes(record.id)))
.map(record => record.id)
)
];
var remindUnpaid = recordIds =>
printRecords(
recordIds.filter(studentId => !getStudentFromId(studentId).paid)
);
// ********************************
var currentEnrollment = [ 410, 105, 664, 375 ];
var studentRecords = [
{ id: 313, name: "Frank", paid: true, },
{ id: 410, name: "Suzy", paid: true, },
{ id: 709, name: "Brian", paid: false, },
{ id: 105, name: "Henry", paid: false, },
{ id: 502, name: "Mary", paid: true, },
{ id: 664, name: "Bob", paid: false, },
{ id: 250, name: "Peter", paid: true, },
{ id: 375, name: "Sarah", paid: true, },
{ id: 867, name: "Greg", paid: false, },
];
printRecords(currentEnrollment);
console.log("----");
currentEnrollment = paidStudentsToEnroll();
printRecords(currentEnrollment);
console.log("----");
remindUnpaid(currentEnrollment);
/*
Bob (664): Not Paid
Henry (105): Not Paid
Sarah (375): Paid
Suzy (410): Paid
----
Bob (664): Not Paid
Frank (313): Paid
Henry (105): Not Paid
Mary (502): Paid
Peter (250): Paid
Sarah (375): Paid
Suzy (410): Paid
----
Bob (664): Not Paid
Henry (105): Not Paid
*/