Advertisement
Guest User

employees

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