Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let tasks = arr.shift().split(' ').map(Number);
- for (const input of arr) {
- task = input.split(' ');
- let command = task.shift();
- if (command === 'Complete') {
- let currentIndex = Number(task[0]);
- if (currentIndex >= 0 && currentIndex < tasks.length - 1) {
- tasks[currentIndex] = 0;
- continue;
- }
- }
- if (command === 'Change') {
- let currentIndex = Number(task[0]);
- let newTime = Number(task[1]);
- if (currentIndex >= 0 && currentIndex < tasks.length - 1) {
- tasks[currentIndex] = newTime;
- continue;
- }
- }
- if (command === 'Drop') {
- let currentIndex = Number(task[0]);
- if (currentIndex >= 0 && currentIndex < tasks.length - 1) {
- tasks[currentIndex] = -1;
- continue;
- }
- }
- if (command === 'Count') {
- let typeOfCommand = task[0];
- if (typeOfCommand === 'Completed') {
- let countCompleted = 0;
- for (const el of tasks) {
- if (el === 0) {
- countCompleted++;
- }
- }
- console.log(countCompleted);
- } else if (typeOfCommand === 'Incomplete') {
- let countIncomplete = 0;
- for (const el of tasks) {
- if (el != 0 && el != -1) {
- countIncomplete++;
- }
- }
- console.log(countIncomplete);
- } else if (typeOfCommand === 'Dropped') {
- let countDropped = 0;
- for (const el of tasks) {
- if (el === -1) {
- countDropped++;
- }
- }
- console.log(countDropped);
- }
- }
- }
- let remainingTasks = tasks.filter(a => a > 0);
- console.log(remainingTasks.join(' '));
- }
- solve([
- '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