Advertisement
Guest User

tasksPlanner

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