SHOW:
|
|
- or go back to the newest paste.
1 | function demoLoops(input) { | |
2 | ||
3 | let index = 0; | |
4 | let command = input[index]; | |
5 | let studentCounter = 0; | |
6 | let standartCounter = 0; | |
7 | let kidCounter = 0; | |
8 | let totalTicketsCounter = 0; | |
9 | ||
10 | while (command !== 'Finish') { | |
11 | let name = command; | |
12 | index++; | |
13 | ||
14 | let freeSpaces = Number(input[index]); | |
15 | index++; | |
16 | ||
17 | let ticketType = input[index]; | |
18 | let ticketCounter = 0; | |
19 | ||
20 | while (ticketType !== 'End') { | |
21 | ticketCounter++; | |
22 | ||
23 | switch (ticketType) { | |
24 | case 'standard': standartCounter++; break; | |
25 | case 'student': studentCounter++; break; | |
26 | case 'kid': kidCounter++; break; | |
27 | ||
28 | } | |
29 | ||
30 | if (ticketCounter >= freeSpaces) { | |
31 | break; | |
32 | } | |
33 | ticketType = input[++index]; | |
34 | } | |
35 | ||
36 | totalTicketsCounter += ticketCounter; | |
37 | let resultSingleFilm = ticketCounter / freeSpaces * 100; | |
38 | ||
39 | console.log(`${name} - ${resultSingleFilm.toFixed(2)}% full.`); | |
40 | ||
41 | command = input[++index]; | |
42 | } | |
43 | ||
44 | console.log(`Total tickets: ${totalTicketsCounter}`); | |
45 | console.log(`${(studentCounter / totalTicketsCounter * 100).toFixed(2)}% student tickets.`); | |
46 | console.log(`${(standartCounter / totalTicketsCounter * 100).toFixed(2)}% standard tickets.`); | |
47 | console.log(`${(kidCounter / totalTicketsCounter * 100).toFixed(2)}% kids tickets.`); | |
48 | } | |
49 | demoLoops([ | |
50 | "Taxi", | |
51 | "10", | |
52 | "standard", | |
53 | "kid", | |
54 | "student", | |
55 | "student", | |
56 | "standard", | |
57 | "standard", | |
58 | "End", | |
59 | "Scary Movie", | |
60 | "6", | |
61 | "student", | |
62 | "student", | |
63 | "student", | |
64 | "student", | |
65 | "student", | |
66 | "student", | |
67 | "Finish"]); |