View difference between Paste ID: ava4yMkS and iZD87sDv
SHOW: | | - or go back to the newest paste.
1
function tseamAccount(input) {
2
    let games = input[0].split(' ');
3
4
    for (let i = 1; i < input.length; i++) {
5
        let currentEl = input[i].split(' ');
6
        let command = currentEl[0];
7
        let newGame = currentEl[1];
8
9
        if (command === 'Play') {
10
            break;
11
12
        } else if (command === "Install") {
13
            let counter = 0;
14
15
            for (let i = 0; i < games.length; i++) {
16
                if (games[i] === newGame) {
17
                    counter++;
18
                    break;
19
                }
20
            }
21
22
            if (counter === 0) {
23
                games.push(newGame);
24
            }
25
        } else if (command === 'Uninstall') {
26
            for (let i = 0; i < games.length; i++) {
27
                if (games[i] === newGame) {
28
                    games.splice(i, 1);
29
                    break;
30
                }
31
            }
32
        } else if (command === 'Update') {
33
            for (let i = 0; i < games.length; i++) {
34
                if (games[i] === newGame) {
35
                    games.splice(i, 1);
36
                    games.push(newGame);
37
                }
38
            }
39
        } else if (command === 'Expansion') {
40
            let expansion = newGame.split('-');
41
            let game = expansion[0];
42
43
            for (let i = 0; i < games.length; i++) {
44
                if (games[i] === game) {
45
                    let expandedGame = expansion.join(':');
46
                    games.splice(i + 1, 0, expandedGame);
47
                    break;
48
                }
49
            }
50
        }
51
    }
52
53
    console.log(games.join(' '));
54
}