Advertisement
Guest User

Untitled

a guest
Oct 28th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function tasksPlanner(arr) {
  2.  
  3. let tasks = arr.shift().split(' ').map(Number);
  4.  
  5. for (let iterator of arr) {
  6. let [command, index, time] = iterator.split(' ');
  7. time = Number(time);
  8. index = Number(index);
  9.  
  10. if (command === 'End') {
  11. break;
  12. }
  13. if (command === 'Complete') {
  14. complete(+index)
  15. }
  16. if (command === 'Change') {
  17. change(+index, time);
  18. }
  19. if(command === 'Drop'){
  20. drop(+index);
  21. }
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. }
  29.  
  30. function complete(index) {
  31. arr.find(function (index) {
  32. arr[i] = 0;
  33. }
  34.  
  35. }
  36. function change(index, time){
  37. if(index >= 0 && index < tasks.length){
  38. tasks[index] = time;
  39. }}
  40.  
  41. function drop(index){
  42. if(index >= 0 && index < tasks.length){
  43. tasks[index] = -1;
  44. arr.filter(index => index >= 0);
  45. }
  46. }
  47.  
  48. console.log(arr);
  49.  
  50. }
  51. tasksPlanner(['1 -1 2 3 4 5 ', 'Complete 4', 'Change 0 4', 'Drop 3', 'Count Dropped', 'End']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement