Created
March 14, 2022 21:45
-
-
Save zt4ff/7fb6fd44b29f2d2fdd92b434dc22f75e to your computer and use it in GitHub Desktop.
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
// index.js | |
let counter = 0; | |
const generateId = () => { | |
++counter; | |
return counter; | |
}; | |
class StudentManagement { | |
#students = []; | |
constructor(students) { | |
this.#students = students.map((student) => { | |
return { id: generateId(), name: student, performance: null }; | |
}); | |
} | |
add(...students) { | |
students.forEach((student) => { | |
this.#students.push({ | |
id: generateId(), | |
name: student, | |
performance: null, | |
}); | |
}); | |
} | |
getStudent(studentIDOrName) { | |
if (studentIDOrName) { | |
return this.#students.filter( | |
(student) => | |
studentIDOrName === student.id || studentIDOrName === student.name | |
); | |
} | |
return this.#students; | |
} | |
score(id, performance) { | |
if (performance >= 0 && performance <= 100) { | |
this.#students.find((student) => { | |
if (student.id === id) { | |
student.performance = performance; | |
} | |
}); | |
} else throw new Error("Score should be between 0 and 100"); | |
} | |
} | |
module.exports = StudentManagement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment