Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/students.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const students: Student[] = [
function getStudentName(student: Student): string {
// write your code here...

return ""; // replace empty string with what you see is fit
return student.name; // replace empty string with what you see is fit
}

/**
Expand All @@ -87,7 +87,7 @@ function getStudentName(student: Student): string {
function getCourse(student: Student, courseIndex: number): string {
// write your code here...

return ""; // replace empty string with what you see is fit
return student.courses[courseIndex]; // replace empty string with what you see is fit
}

/**
Expand All @@ -103,7 +103,7 @@ function getCourse(student: Student, courseIndex: number): string {
*/
function addCourseToStudent(student: Student, course: string): Student {
// write your code here...

student.courses.push(course)
return student;
}

Expand All @@ -117,7 +117,7 @@ function addCourseToStudent(student: Student, course: string): Student {
function countCourses(student: Student): number {
// write your code here...

return -1; // replace -1 with what you see is fit
return student.courses.length; // replace -1 with what you see is fit
}

/**
Expand All @@ -133,8 +133,10 @@ function countCourses(student: Student): number {
*/
function removeCourseFromStudent(student: Student, course: string): Student {
// write your code here...

return student;
return {
...student,
courses: student.courses.filter((c) => c !== course),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever, but it would be preferable to do this:

student.courses = student.courses.filter((c) => c !== course);
return student;

This way we don't break the reference to the original object

}

/**
Expand All @@ -156,7 +158,7 @@ function findStudentById(
): Student | undefined {
// write your code here...

return undefined; // replace undefined with what you see is fit
return students.find((student) => student.id === studentId); // replace undefined with what you see is fit
}

export {
Expand Down
Loading