Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var school = (function() {
- var students = [];
- var teachers = [];
- function addStudent(name, grade) {
- students.push({
- name : name,
- grade : grade
- });
- }
- function addTeacher(name, speciality) {
- teachers.push({
- name : name,
- speciality : speciality
- });
- }
- function getTeachers(speciality) {
- return teachers.filter(function(t){
- return t.speciality === speciality
- });
- }
- function getStudents(grade) {
- return students.filter(function(s){
- return s.grade === grade
- });
- }
- return {
- as: addStudent,
- at: addTeacher,
- gs: getStudents,
- gt: getTeachers
- };
- })();
- school.as("ivan", 5);
- school.as("ivanka", 6);
- school.at("gogo", "maths");
- school.at("gergana", "maths");
- console.log(school.gs(5));
- console.log(school.gt("maths"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement