View difference between Paste ID: vfysrUUb and vuN7Qy5R
SHOW: | | - or go back to the newest paste.
1
solve = (() => {
2
    const commands = {
3
        upvote: (post) => post.upvotes++,
4
        downvote: (post) => post.downvotes++,
5
        score: (post) => {
6
            let {upvotes, downvotes} = post;
7
            let total = upvotes + downvotes;
8
            // let balance = upvotes - downvotes;
9
 
10
            let obfuscated = Math.ceil(0.25 * Math.max(upvotes,downvotes));
11
            let obfuscatedUpVotes = upvotes + obfuscated;
12
            let obfuscatedDownVotes = downvotes + obfuscated;
13
            let balance = obfuscatedUpVotes - obfuscatedDownVotes;
14
15
            let rating = '';
16
 
17
            if (total < 10) {
18
              rating = 'new';
19
            } else if (upvotes > total * 0.66) {
20
              rating = 'hot';
21
            } else if (balance >= 0 && (upvotes > 100 || downvotes > 100)) {
22
              rating = 'controversial';
23
            } else if (balance < 0) {
24
              rating = 'unpopular';
25
            } else {
26
              rating = 'new';
27
            }
28
             if (total > 50) {
29
                 return [obfuscatedUpVotes, obfuscatedDownVotes, balance, rating];
30
            }
31
            return [upvotes, downvotes, balance, rating];
32
          }
33
    };
34
 
35
    return {call:(post, command) => commands[command](post)}
36
})();