Skip to content

Instantly share code, notes, and snippets.

@furqanbaqai
Created May 21, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furqanbaqai/8b0c9be3ff11b1bb494d252036f6178a to your computer and use it in GitHub Desktop.
Save furqanbaqai/8b0c9be3ff11b1bb494d252036f6178a to your computer and use it in GitHub Desktop.
One more abstraction of the gradeschool.ts
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