Advertisement
Liliana797979

monkey patcher 1- js advanced

Oct 1st, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function result(command) {
  2.  
  3.   if (command === 'upvote') return this.upvotes++;
  4.   if (command === 'downvote') return this.downvotes++;
  5.  
  6.   let upvote = this.upvotes;
  7.   let downvote = this.downvotes;
  8.   let totalVotes = upvote + downvote;
  9.   let balance = upvote - downvote;
  10.  
  11.   function ratingState() {
  12.     if (totalVotes < 10) return 'new';
  13.     if (upvote > totalVotes * 0.66) return 'hot';
  14.     if (balance >= 0 && totalVotes > 100) return 'controversial';
  15.     if (balance < 0) return 'unpopular';
  16.     return 'new';
  17.   }
  18.  
  19.   if (totalVotes > 50) {
  20.     let inflateVote = Math.ceil(Math.max(upvote, downvote) * 0.25);
  21.     return [upvote + inflateVote, downvote + inflateVote, balance, ratingState()];
  22.   }
  23.  
  24.   return [upvote, downvote, balance, ratingState.call(this)];
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement