Advertisement
Btwonu

2

Oct 24th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solveClasses() {
  2.   class Developer {
  3.     constructor(firstName, lastName) {
  4.       this.firstName = firstName;
  5.       this.lastName = lastName;
  6.       this.baseSalary = 1000;
  7.       this.tasks = [];
  8.       this.experience = 0;
  9.     }
  10.  
  11.     addTask(id, taskName, priority) {
  12.       const taskObj = {
  13.         id,
  14.         taskName,
  15.         priority,
  16.       };
  17.  
  18.       if (priority == 'high') {
  19.         this.tasks.unshift(taskObj);
  20.       } else {
  21.         this.tasks.push(taskObj);
  22.       }
  23.  
  24.       return `Task id ${id}, with ${priority} priority, has been added.`;
  25.     }
  26.  
  27.     doTask() {
  28.       // if tasks is empty
  29.       if (this.tasks.length == 0) {
  30.         return `${this.firstName}, you have finished all your tasks. You can rest now.`;
  31.       }
  32.  
  33.       let currentTask = this.tasks.shift();
  34.       return currentTask.taskName;
  35.     }
  36.  
  37.     getSalary() {
  38.       return `${this.firstName} ${this.lastName} has a salary of: ${this.baseSalary}`;
  39.     }
  40.  
  41.     reviewTasks() {
  42.       let output = [];
  43.       output.push('Tasks, that need to be completed:');
  44.  
  45.       this.tasks.forEach((task) => {
  46.         let line = `${task.id}: ${task.taskName} - ${task.priority}`;
  47.         output.push(line);
  48.       });
  49.  
  50.       return output.join('\n');
  51.     }
  52.   }
  53.  
  54.   class Junior extends Developer {
  55.     constructor(firstName, lastName, bonus, experience) {
  56.       super(firstName, lastName);
  57.       this.baseSalary += Number(bonus);
  58.       this.experience = Number(experience);
  59.     }
  60.  
  61.     learn(years) {
  62.       this.experience += Number(years);
  63.     }
  64.   }
  65.  
  66.   class Senior extends Developer {
  67.     constructor(firstName, lastName, bonus, experience) {
  68.       super(firstName, lastName);
  69.       this.baseSalary += Number(bonus);
  70.       this.experience = Number(experience) + 5;
  71.     }
  72.  
  73.     changeTaskPriority(taskId) {
  74.       let currentTask = this.tasks.find((taskObj) => {
  75.         return taskObj.id === taskId;
  76.       });
  77.  
  78.       let currentTaskIndex = this.tasks.indexOf(currentTask);
  79.  
  80.       if (currentTask.priority === 'high') {
  81.         currentTask.priority = 'low';
  82.         this.tasks.splice(currentTaskIndex, 1);
  83.         this.tasks.push(currentTask);
  84.       } else {
  85.         currentTask.priority = 'high';
  86.         this.tasks.splice(currentTaskIndex, 1);
  87.         this.tasks.unshift(currentTask);
  88.       }
  89.  
  90.       return currentTask;
  91.     }
  92.   }
  93.  
  94.   return {
  95.     Developer,
  96.     Junior,
  97.     Senior,
  98.   };
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement