Introduction

Hello, Space Explorer! Today, we’re going to explore an important concept in TypeScript: managing data using arrays and objects with the added power of type safety. To practice this concept, we will build a simple Student Management System. Specifically, we will create a class that stores students and their grades. This hands-on approach will help us understand how arrays and objects can be efficiently utilized with TypeScript's type system to enhance code safety and predictability. Ready to take on this task? Awesome, let's get started!

Introducing Methods to Implement

Our task involves implementing three primary methods within our class:

  1. addStudent(name: string, grade: number): void: Allows us to add a new student and their grade to our list. If the student is already on the list, their grade will be updated.
  2. getGrade(name: string): number | null: Retrieves the grade for a student given their name. Returns null if the student is not found.
  3. removeStudent(name: string): boolean: Removes a student from the list by their name. Returns true if the operation is successful and false if the student is not found.

Understanding the input and output types not only assists in code clarity but also prevents common runtime errors. Let’s break it down step-by-step.

Step 1: Setting up the Class
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal