• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 27th, 2020 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function solve(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) {
30.         }
31.     }
32.     function change(index, time) {
33.         if (index >= 0 && index < tasks.length) {
35.         }
36.     }
37.     function drop(index) {
38.         if (index >= 0 && index < tasks.length) {
40.         }
41.     }
42.     console.log(tasks.filter(t => t > 0).join(' '));
43. }
44. solve([`1 -1 2 3 4 5`,
45.     `Complete 4`,
46.     `Change 0 4`,
47.     `Drop 3`,
48.     `Count Dropped`,
49.     `End`
50.     ])
51.
52.
53. solve([`1 2 3 4 5 4 0 3 2 1`,
54.     `Complete 0`,
55.     `Complete 1`,
56.     `Complete 2`,
57.     `Drop 3`,
58.     `Change 4 1`,
59.     `Count Completed`,
60.     `End`
61.     ])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top