diff --git a/src/challenge.ts b/src/challenge.ts index fad2280..3d1217d 100644 --- a/src/challenge.ts +++ b/src/challenge.ts @@ -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 } /** diff --git a/src/students.ts b/src/students.ts index ac9d6c0..ae7fe37 100644 --- a/src/students.ts +++ b/src/students.ts @@ -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 } /** @@ -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 } /** @@ -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; } @@ -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 } /** @@ -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; } @@ -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 }