Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import { Student } from "./students";
*/
function getStudentsByCourse(students: Student[], course: string): Student[] {
// write your code here...
// students.filter((s) => s.courses);
//const student = students.filter((student) => {
//if(student.courses.forEach(x=>x === course))

return []; // replace empty array with what you see is fit
//});
return students; // replace empty array with what you see is fit
}

/**
Expand Down
15 changes: 11 additions & 4 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 @@ -134,6 +134,11 @@ function countCourses(student: Student): number {
function removeCourseFromStudent(student: Student, course: string): Student {
// write your code here...

student.courses.forEach((item, index) => {
if (item === course) {
student.courses.splice(index, 1);
}
});
return student;
}

Expand All @@ -155,6 +160,8 @@ function findStudentById(
studentId: number
): Student | undefined {
// write your code here...
const studID = students.find((m) => m.id === studentId);
if (studID) return studID;

return undefined; // replace undefined with what you see is fit
}
Expand Down
Loading