-
Notifications
You must be signed in to change notification settings - Fork 0
/
homework.js
271 lines (257 loc) · 6.44 KB
/
homework.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// DATA
const courses = [
{
section: "INF310",
title: "Modern JavaScript",
instructor: "Mikov",
department: "INF",
credits: 1
},
{
section: "INF240",
title: "Website Development",
instructor: "Dimitrov",
department: "INF",
credits: 3
},
{
section: "INF280",
title: "Database Systems",
instructor: "Christozov",
department: "INF",
credits: 3
},
{
section: "MAT104",
title: "Calculus II",
instructor: "Dalakov",
department: "MAT",
credits: 3
},
{
section: "COS221",
title: "Fundamental Data Structures",
instructor: "Christozov",
department: "COS",
credits: 3
},
{
section: "BUS260",
title: "Marketing",
instructor: "Petkov",
department: "BUS",
credits: 3
},
{
section: "BUS300",
title: "Business Ethics",
instructor: "Schwartz",
department: "BUS",
credits: 4
},
{
section: "BUS220",
title: "Financial Accounting",
instructor: "Cleary",
department: "BUS",
credits: 3
},
{
section: "BUS448",
title: "Strategic Management",
instructor: "Pantelides",
department: "BUS",
credits: 3
},
{
section: "THR130",
title: "Beginning Acting",
instructor: "Delchev",
department: "FAR",
credits: 3
},
{
section: "ENG205",
title: "Creative Writing",
instructor: "Cohen",
department: "ENG",
credits: 4
}
];
const students = [
{
name: "Adam Banff",
standing: "Junior",
courses: ["INF240", "BUS220", "ENG205"]
},
{
name: "Betty Cahn",
standing: "Senior",
courses: ["INF280", "COS221", "INF310"]
},
{
name: "Chisto Dotev",
standing: "Senior",
courses: ["BUS220", "BUS448", "THR130"]
},
{
name: "Dani Emerson",
standing: "Sophomore",
courses: ["ENG205", "THR130", "INF310"]
},
{
name: "Emy Fang",
standing: "Senior",
courses: ["BUS300", "BUS260", "BUS448"]
},
{
name: "Filip Gomez",
standing: "Junior",
courses: ["COS221", "COS310", "INF240"]
},
{
name: "Gergana Harris",
standing: "Senior",
courses: ["BUS448", "ENG205", "THR130"]
},
{
name: "Harry Insman",
standing: "Senior",
courses: ["INF310", "ENG205", "THR130"]
},
{
name: "Iliana Johnes",
standing: "Sophomore",
courses: ["BUS260", "BUS300", "ENG205"]
},
{
name: "Jane Kelly",
standing: "Sophomore",
courses: ["BUS220", "BUS260", "THR130"]
}
];
// STUDENT NAMES
const studentNames = students.map(student => student.name);
console.log(studentNames);
// STUDENTS PER COURSE
const studentsPerCourse = {};
for (let student of students) {
for (let course of student.courses) {
if (!studentsPerCourse[course]) {
studentsPerCourse[course] = 0;
}
studentsPerCourse[course] += 1;
}
}
console.log("STUDENTS PER COURSE");
console.log(studentsPerCourse);
// THE MOST STDUENTS INVOLVED
let mostInvolved = Object.values(studentsPerCourse)[0];
for (let x = 0; x < Object.values(studentsPerCourse).length; x++) {
if (Object.values(studentsPerCourse)[x] > mostInvolved) {
mostInvolved = Object.values(studentsPerCourse)[x];
}
}
console.log("THE MOST STUDENTS INVOLVED");
console.log(mostInvolved);
// THE FEWEST STDUENTS INVOLVED
let fewestInvolved = Object.values(studentsPerCourse)[0];
for (let x = 0; x < Object.values(studentsPerCourse).length; x++) {
if (Object.values(studentsPerCourse)[x] < fewestInvolved) {
fewestInvolved = Object.values(studentsPerCourse)[x];
}
}
console.log("THE FEWEST STUDENTS INVOLVED");
console.log(fewestInvolved);
// STUDENTS PER STANDING
const studentsByStanding = {};
for (let student of students) {
if (!studentsByStanding[student.standing]) {
studentsByStanding[student.standing] = 0;
}
studentsByStanding[student.standing] += 1;
}
console.log("STUDENTS PER STANDING");
console.log(studentsByStanding);
// COURSES BY DEPARTMENT
const coursesByDepartment = {};
for (let course of courses) {
if (!coursesByDepartment[course.department]) {
coursesByDepartment[course.department] = 0;
}
coursesByDepartment[course.department] += 1;
}
console.log("COURSES BY DEPARTMENT");
console.log(coursesByDepartment);
// COURSES PER DEPARTMENT
const coursesPerDepartment = {};
for (let course of courses) {
coursesPerDepartment[course.section] = course.department;
}
console.log("COURSES PER DEPARTMENT");
console.log(coursesPerDepartment);
const departmentsCourses = Object.keys(coursesPerDepartment);
const sectionCourses = Object.values(coursesPerDepartment);
// STUDENTS BY DEPARTMENT
// We have students per course, course by department
// INSTRUCTOR PER COURSE
const instructorPerCourse = {};
for (let course of courses) {
instructorPerCourse[course.section] = course.instructor;
}
console.log("INSTRUCTOR PER COURSE");
console.log(instructorPerCourse);
// STUDENTS PER INSTRUCTOR
/*
const studentsPerInstructor = {};
for (let student of students) {
const instructorsOfStudent = [];
for (let course of student.courses) {
const courseInstructor = instructorPerCourse[course];
if (!instructorsOfStudent.includes(courseInstructor)) {
instructorsOfStudent.push(courseInstructor);
}
}
for (let instructor of instructorsOfStudent) {
studentsPerInstructor[instructor] += 1;
console.log("STUDENTS PER INSTRUCTOR");
console.log(instructorsOfStudent);
}
}
*/
// WHAT MAJOR
// what courses each student is taking
const studentTaking = {};
for (let student of students) {
studentTaking[student.name] = student.courses;
}
console.log("STUDENT IS TAKING");
console.log(studentTaking);
// find what courses are from which department
const whichDepartment = {};
for (let course of courses) {
whichDepartment[course.section] = course.department;
}
console.log("Each course with its department");
console.log(whichDepartment);
// Replacing courses names with department
const replace = {};
for (let course of courses) {
if (studentTaking[courses] === Object.keys(whichDepartment)) {
replace = studentTaking.courses = whichDepartment[departemnt];
}
}
console.log(replace);
// STUDENTS WITH BIGGEST SUM OF CREDITS FOR THEIR ENROLLED CLASSES
// What courses each student takes
const creditsWinner = {};
console.log(studentTaking);
// The amount of credits per course
const creditsForCourse = {};
for (let course of courses) {
creditsForCourse[course.section] = course.credits;
}
console.log("Each course with its credits");
console.log(creditsForCourse);
// substitute courses with its credits
// using splice?