Aliendreamer

monkey patcher

Feb 17th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(cmd){
  2.     let post=this;
  3.     let obj=(()=>{    
  4.     function upvote() {post.upvotes+=1;};
  5.     function downvote() {post.downvotes+=1;};
  6.     function score(){
  7.    
  8.         let totalPosts=post.downvotes+post.upvotes;
  9.         let mostRatings=post.downvotes>=post.upvotes?post.downvotes:post.upvotes;
  10.        
  11.         let PositiveVibe=post.upvotes/totalPosts*100>66;
  12.         let NegativeVibe=post.downvotes/totalPosts*100>50;
  13.         let votesOverHundred=post.downvotes>=100?true:post.upvotes>=100?true:false;
  14.         let rating;
  15.         if(totalPosts<10){
  16.           rating='new';
  17.         }else if(totalPosts>10 && !PositiveVibe && !NegativeVibe && !votesOverHundred){
  18.             rating='new';
  19.         }
  20.         else if(PositiveVibe){
  21.           rating='hot';
  22.         }else if(!NegativeVibe && votesOverHundred){
  23.           rating='controversial';      
  24.         }else{
  25.             rating='unpopular';
  26.         }
  27.         let difference=post.upvotes-post.downvotes;
  28.         if(totalPosts>50){
  29.         let bonusComments=Math.ceil(mostRatings*0.25);
  30.         let result=[post.upvotes+bonusComments,post.downvotes+bonusComments,difference];
  31.         result.push(rating)
  32.         return result;
  33.       }
  34.       let resultNotTampered=[post.upvotes,post.downvotes,difference];
  35.       resultNotTampered.push(rating)
  36.       return resultNotTampered;
  37.     };
  38.    
  39.     return  {upvote,downvote,score}
  40. })();
  41. return obj[cmd]();
  42. };
Advertisement
Add Comment
Please, Sign In to add comment