Created
May 21, 2020 20:20
-
-
Save furqanbaqai/8b0c9be3ff11b1bb494d252036f6178a to your computer and use it in GitHub Desktop.
One more abstraction of the gradeschool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GradeSchool{ | |
private _studentRoster: Map<number,string[]> = new Map(); | |
public studentRoster(): Map<string,string[]> { | |
const rosterMap: Map<string,string[]> = new Map(); | |
for(const key of this._studentRoster.keys()){ | |
rosterMap.set(key.toString(),this.studentsInGrade(key)); | |
} | |
return rosterMap; | |
} | |
public addStudent(name: string, grade: number){ | |
let studArray: string[] = this.studentsInGrade(grade).concat(name); | |
this._studentRoster.set(grade,studArray); | |
} | |
public studentsInGrade(grade: number): string[]{ | |
return [...(this._studentRoster.get(grade)|| []).sort()]; | |
} | |
} | |
export default GradeSchool; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment