Advertisement
GalinaKG

task 1 Exam Js Front-end my decision

Apr 9th, 2023 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. function sprintReview(input) {
  2. let n = Number(input.shift())
  3. let data = {};
  4. let points = {
  5. ToDo: 0,
  6. 'In Progress': 0,
  7. 'Code Review': 0,
  8. Done: 0
  9. }
  10.  
  11. for (let i = 0; i < n; i++) {
  12. let [assignee, taskId, title, status, estimatedPoints] = input[i].split(':');
  13. if (!data.hasOwnProperty(assignee)) {
  14. data[assignee] = [];
  15. }
  16. data[assignee].push({taskId, title, status, estimatedPoints});
  17. points[status] += Number(estimatedPoints);
  18. }
  19. for (let i = 0; i < n; i++) {
  20. input.shift();
  21. }
  22.  
  23. for (let line of input) {
  24. let command = line.split(':')[0];
  25. let assignee = line.split(':')[1];
  26.  
  27. if (!data.hasOwnProperty(assignee)) {
  28. console.log(`Assignee ${assignee} does not exist on the board!`);
  29. continue;
  30. }
  31.  
  32. if (command == 'Add New') {
  33. let [taskId, title, status, estimatedPoints] = line.split(':').slice(2, line.length);
  34. data[assignee].push({ taskId, title, status, estimatedPoints });
  35. points[status] += Number(estimatedPoints);
  36.  
  37. } else if (command == 'Change Status') {
  38. let [taskId, newStatus] = line.split(':').slice(2, line.length);
  39. for (let obj of data[assignee]) {
  40. if (obj.taskId == taskId) {
  41. points[obj.status] -= obj.estimatedPoints;
  42. obj.status = newStatus;
  43. points[newStatus] += Number(obj.estimatedPoints);
  44. } else {
  45. console.log(`Task with ID ${taskId} does not exist for ${assignee}!`);
  46. }
  47. }
  48.  
  49. } else if (command == 'Remove Task') {
  50. let [assignee, index] = line.split(':').slice(1, line.length);
  51. if (index < 0 || index >= data[assignee].length) {
  52. console.log("Index is out of range!");
  53. continue;
  54. }
  55. let pointsForRemove = data[assignee][index].estimatedPoints;
  56. let currStatus = data[assignee][index].status;
  57. points[currStatus] -= pointsForRemove;
  58. data[assignee].splice(index, 1);
  59. }
  60. }
  61.  
  62. console.log(`ToDo: ${points['ToDo']}pts`)
  63. console.log(`In Progress: ${points['In Progress']}pts`);
  64. console.log(`Code Review: ${points['Code Review']}pts`);
  65. console.log(`Done Points: ${points['Done']}pts`);
  66.  
  67. if (points['Done'] >= (points['ToDo'] + points['In Progress'] + points['Code Review'])) {
  68. console.log('Sprint was successful!');
  69. } else {
  70. console.log('Sprint was unsuccessful...');
  71. }
  72. }
  73.  
  74. sprintReview([
  75. '5',
  76. 'Kiril:BOP-1209:Fix Minor Bug:ToDo:3',
  77. 'Mariya:BOP-1210:Fix Major Bug:In Progress:3',
  78. 'Peter:BOP-1211:POC:Code Review:5',
  79. 'Georgi:BOP-1212:Investigation Task:Done:2',
  80. 'Mariya:BOP-1213:New Account Page:In Progress:13',
  81. 'Add New:Kiril:BOP-1217:Add Info Page:In Progress:5',
  82. 'Change Status:Peter:BOP-1290:ToDo',
  83. 'Remove Task:Mariya:1',
  84. 'Remove Task:Joro:1',
  85. ]);
  86.  
  87. // sprintReview( [
  88. // '4',
  89. // 'Kiril:BOP-1213:Fix Typo:Done:1',
  90. // 'Peter:BOP-1214:New Products Page:In Progress:2',
  91. // 'Mariya:BOP-1215:Setup Routing:ToDo:8',
  92. // 'Georgi:BOP-1216:Add Business Card:Code Review:3',
  93. // 'Add New:Sam:BOP-1237:Testing Home Page:Done:3',
  94. // 'Change Status:Georgi:BOP-1216:Done',
  95. // 'Change Status:Will:BOP-1212:In Progress',
  96. // 'Remove Task:Georgi:3',
  97. // 'Change Status:Mariya:BOP-1215:Done',
  98. // ]
  99. // );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement