igrilkul

Untitled

Jun 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let solution = {
  2.         call:function(object,argument){
  3.  
  4.             switch (argument)
  5.             {
  6.                 case 'upvote':
  7.                 {
  8.                     object.upvotes+=1;
  9.                     break;
  10.                 }
  11.  
  12.                 case 'downvote':
  13.                 {
  14.                     object.downvotes+=1;
  15.                     break;
  16.                 }
  17.  
  18.                 case 'score':
  19.                 {
  20.                     let result=[];
  21.                     let upvotes = Number(object.upvotes);
  22.                     let downvotes = Number(object.downvotes);
  23.  
  24.                     let reportedUpvotes;
  25.                     let reportedDownvotes;
  26.                     let difference = upvotes-downvotes;
  27.                     let rating;
  28.                     if(upvotes+downvotes>50)
  29.                     {
  30.                         let inflation = Math.max(upvotes,downvotes);
  31.                         reportedDownvotes=downvotes+0.25*inflation;
  32.                         reportedUpvotes=upvotes+0.25*inflation;
  33.                     }
  34.                     else
  35.                     {
  36.                         reportedUpvotes=upvotes;
  37.                         reportedDownvotes=downvotes;
  38.                     }
  39.  
  40.  
  41.                     if(upvotes>0.66*(upvotes+downvotes) && upvotes+downvotes>=10)
  42.                     {
  43.                         rating='hot';
  44.                     }
  45.                     else if(upvotes>100 && downvotes>100)
  46.                     {
  47.                         if(difference>0)
  48.                         {
  49.                             rating='controversial';
  50.                         }
  51.                         else
  52.                         {
  53.                             rating='unpopular';
  54.                         }
  55.                     }
  56.                     else
  57.                     {
  58.                         rating='new';
  59.                     }
  60.  
  61.                     return [reportedUpvotes,reportedDownvotes,difference,rating];
  62.  
  63.  
  64.                 }
  65.             }
  66.         }
  67.  
  68.  
  69. };
  70.  
  71. var forumPost = {
  72.     id: '1',
  73.     author: 'pesho',
  74.     content: 'hi guys',
  75.     upvotes: 0,
  76.     downvotes: 0
  77. };
  78.  
  79. solution.call(forumPost, 'upvote');
  80. console.log(solution.call(forumPost,'score'));
Advertisement
Add Comment
Please, Sign In to add comment