Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveClasses() {
- class Developer {
- constructor(firstName, lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- this.baseSalary = 1000;
- this.tasks = [];
- this.experience = 0;
- }
- addTask(id, taskName, priority) {
- const taskObj = {
- id,
- taskName,
- priority,
- };
- if (priority == 'high') {
- this.tasks.unshift(taskObj);
- } else {
- this.tasks.push(taskObj);
- }
- return `Task id ${id}, with ${priority} priority, has been added.`;
- }
- doTask() {
- // if tasks is empty
- if (this.tasks.length == 0) {
- return `${this.firstName}, you have finished all your tasks. You can rest now.`;
- }
- let currentTask = this.tasks.shift();
- return currentTask.taskName;
- }
- getSalary() {
- return `${this.firstName} ${this.lastName} has a salary of: ${this.baseSalary}`;
- }
- reviewTasks() {
- let output = [];
- output.push('Tasks, that need to be completed:');
- this.tasks.forEach((task) => {
- let line = `${task.id}: ${task.taskName} - ${task.priority}`;
- output.push(line);
- });
- return output.join('\n');
- }
- }
- class Junior extends Developer {
- constructor(firstName, lastName, bonus, experience) {
- super(firstName, lastName);
- this.baseSalary += Number(bonus);
- this.experience = Number(experience);
- }
- learn(years) {
- this.experience += Number(years);
- }
- }
- class Senior extends Developer {
- constructor(firstName, lastName, bonus, experience) {
- super(firstName, lastName);
- this.baseSalary += Number(bonus);
- this.experience = Number(experience) + 5;
- }
- changeTaskPriority(taskId) {
- let currentTask = this.tasks.find((taskObj) => {
- return taskObj.id === taskId;
- });
- let currentTaskIndex = this.tasks.indexOf(currentTask);
- if (currentTask.priority === 'high') {
- currentTask.priority = 'low';
- this.tasks.splice(currentTaskIndex, 1);
- this.tasks.push(currentTask);
- } else {
- currentTask.priority = 'high';
- this.tasks.splice(currentTaskIndex, 1);
- this.tasks.unshift(currentTask);
- }
- return currentTask;
- }
- }
- return {
- Developer,
- Junior,
- Senior,
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement