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) {
- if (priority == "high") {
- this.tasks.unshift({ id, taskName, priority });
- } else {
- this.tasks.push({ id, taskName, priority });
- }
- return `Task id ${id}, with ${priority} priority, has been added.`
- }
- doTask() {
- if (this.tasks.length > 0) {
- return this.tasks.shift();
- } else {
- return `${this.firstName}, you have finished all your tasks. You can rest now.`
- }
- }
- getSalary() {
- return `${this.firstName} ${this.lastName} has a salary of: ${this.baseSalary}`;
- }
- reviewTasks() {
- let res = [];
- res.push("Tasks, that need to be completed:")
- this.tasks.forEach(x => {
- res.push(`${x.id}: ${x.taskName} - ${x.priority}`);
- })
- return res.join('\n');
- }
- }
- class Junior extends Developer {
- constructor(firstName, lastName, bonus, experience) {
- super(firstName, lastName);
- this.experience = experience;
- this.baseSalary = 1000 + bonus;
- }
- learn(years) {
- this.experience += years;
- }
- }
- class Senior extends Developer {
- constructor(firstName, lastName, bonus, experience) {
- super(firstName, lastName);
- this.experience = experience + 5;
- this.baseSalary = 1000 + bonus;
- }
- changeTaskPriority(taskId) {
- let taskIndex = this.tasks.findIndex(x => x.id == taskId);
- let currTask = this.tasks[taskIndex];
- this.tasks = this.tasks.splice(taskIndex, 1);
- if (currTask.priority == 'low') {
- currTask.priority = 'high'
- this.tasks.unshift(currTask);
- } else {
- currTask.priority = 'low';
- this.tasks.push(currTask);
- }
- return currTask;
- }
- }
- return {
- Developer,
- Junior,
- Senior
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment