Професионална програма
Loading...
Axiomatik avatar Axiomatik 1135 Точки
Best Answer

Just 2 issues:

1. Validation for the rating had to include if(total < 10) in the validation-chain.

2. Up and down-votes had to be increased by 25% by default and the required balance of votes based upon them, the minimum-requirement for 50 votes determined whether the true or increased numbers had to be inserted in the report.

Code(100%):

solve = (() => {
    const commands = {
        upvote: (post) => post.upvotes++,
        downvote: (post) => post.downvotes++,
        score: (post) => {
            let {upvotes, downvotes} = post;
            let total = upvotes + downvotes;
            // let balance = upvotes - downvotes;
 
            let obfuscated = Math.ceil(0.25 * Math.max(upvotes,downvotes));
            let obfuscatedUpVotes = upvotes + obfuscated;
            let obfuscatedDownVotes = downvotes + obfuscated;
            let balance = obfuscatedUpVotes - obfuscatedDownVotes;

            let rating = '';
 
            if (total < 10) {
              rating = 'new';
            } else if (upvotes > total * 0.66) {
              rating = 'hot';
            } else if (balance >= 0 && (upvotes > 100 || downvotes > 100)) {
              rating = 'controversial';
            } else if (balance < 0) {
              rating = 'unpopular';
            } else {
              rating = 'new';
            }
             if (total > 50) {
                 return [obfuscatedUpVotes, obfuscatedDownVotes, balance, rating];
            }
            return [upvotes, downvotes, balance, rating];
          }
    };
 
    return {call:(post, command) => commands[command](post)}
})();

0
sasho91 avatar sasho91 16 Точки

Thank you very much! :)

0