MartenBG

Tasks Planner

Oct 30th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. function solve(arr) {
  2.  
  3.  
  4. let tasks = arr.shift().split(' ').map(Number);
  5.  
  6. for (const input of arr) {
  7.  
  8. task = input.split(' ');
  9. let command = task.shift();
  10.  
  11. if (command === 'Complete') {
  12.  
  13. let currentIndex = Number(task[0]);
  14. if (currentIndex >= 0 && currentIndex < tasks.length - 1) {
  15. tasks[currentIndex] = 0;
  16. continue;
  17. }
  18.  
  19. }
  20. if (command === 'Change') {
  21.  
  22. let currentIndex = Number(task[0]);
  23. let newTime = Number(task[1]);
  24. if (currentIndex >= 0 && currentIndex < tasks.length - 1) {
  25. tasks[currentIndex] = newTime;
  26. continue;
  27. }
  28. }
  29. if (command === 'Drop') {
  30.  
  31. let currentIndex = Number(task[0]);
  32. if (currentIndex >= 0 && currentIndex < tasks.length - 1) {
  33. tasks[currentIndex] = -1;
  34. continue;
  35. }
  36.  
  37. }
  38. if (command === 'Count') {
  39. let typeOfCommand = task[0];
  40. if (typeOfCommand === 'Completed') {
  41. let countCompleted = 0;
  42. for (const el of tasks) {
  43. if (el === 0) {
  44. countCompleted++;
  45. }
  46. }
  47. console.log(countCompleted);
  48. } else if (typeOfCommand === 'Incomplete') {
  49. let countIncomplete = 0;
  50. for (const el of tasks) {
  51. if (el != 0 && el != -1) {
  52. countIncomplete++;
  53. }
  54. }
  55. console.log(countIncomplete);
  56. } else if (typeOfCommand === 'Dropped') {
  57. let countDropped = 0;
  58. for (const el of tasks) {
  59. if (el === -1) {
  60. countDropped++;
  61. }
  62. }
  63. console.log(countDropped);
  64. }
  65.  
  66. }
  67.  
  68. }
  69.  
  70. let remainingTasks = tasks.filter(a => a > 0);
  71.  
  72. console.log(remainingTasks.join(' '));
  73.  
  74.  
  75. }
  76.  
  77.  
  78. solve([
  79. '1 -1 2 3 4 5',
  80. 'Complete 4',
  81. 'Change 0 4',
  82. 'Drop 3',
  83. 'Count Dropped',
  84. 'End'
  85. ]);
Advertisement
Add Comment
Please, Sign In to add comment