diff --git a/src/students.ts b/src/students.ts index ac9d6c0..0faa2cf 100644 --- a/src/students.ts +++ b/src/students.ts @@ -70,11 +70,9 @@ const students: Student[] = [ * getStudentName(students[0]); // => "Alice" */ 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 } - +console.log(getStudentName(students[0])); /** * `getCourse` function: * - Accepts: @@ -85,11 +83,9 @@ function getStudentName(student: Student): string { * getCourse(students[4], 2); // => "Music" */ 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 } - +console.log(getCourse(students[4], 2)); /** * `addCourseToStudent` function: * - Accepts: @@ -102,10 +98,11 @@ function getCourse(student: Student, courseIndex: number): string { * // => { id: 8, name: "Helen", courses: ["History", "Art", "PE", "Physics"] } */ function addCourseToStudent(student: Student, course: string): Student { - // write your code here... + student.courses.push(course); return student; } +console.log(addCourseToStudent(students[7], "phy")); /** * `countCourses` function: @@ -115,9 +112,7 @@ function addCourseToStudent(student: Student, course: string): Student { * countCourses(students[1]); // => 4 */ 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 } /** @@ -132,7 +127,10 @@ function countCourses(student: Student): number { * // => { id: 7, name: "Grace", courses: ["Math", "English", "Music"] } */ function removeCourseFromStudent(student: Student, course: string): Student { - // write your code here... + const rArry = student.courses.indexOf(course); + if (rArry !== -1) { + student.courses.splice(rArry, 1); + } return student; } @@ -154,11 +152,11 @@ function findStudentById( students: Student[], studentId: number ): Student | undefined { - // write your code here... - - return undefined; // replace undefined with what you see is fit + return students.find((sf) => sf.id === studentId); // replace undefined with what you see is fit } +console.log(findStudentById(students, 10)); + export { Student, getStudentName,