daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const calculateEarnedMerit = function(activity, rawMerit){
  2.  
  3.   const meritStartDate = new Date("January 24, 2018")
  4.  
  5.   const today = Date.now()
  6.  
  7.   const startMerits = {
  8.   "Brand new": 0,
  9.   "Newbie":0,
  10.   "Jr Member": 1,
  11.   "Member": 10,
  12.   "Full Member": 100,
  13.   "Sr. Member": 250,
  14.   "Hero Member": 500,
  15.   "Legendary": 1000
  16.   }
  17.  
  18.   const activityRequirements = {
  19.     0: "Brand new",
  20.     1: "Newbie",
  21.     30: "Jr Member",
  22.     60: "Member",
  23.     120: "Full Member",
  24.     240: "Sr. Member",
  25.     480: "Hero Member",
  26.     //average activity of freshly ranked-up Legendary
  27.     902: "Legendary"
  28.   }
  29.   //activity at the day of merit system introduction
  30.   //assuming that activity is maxed out between today and meritStartDate
  31.   let a = Math.max(activity - Math.floor((today - meritStartDate)/(1000*60*60*24)),0)
  32.  
  33.   const k = Object.keys(activityRequirements)
  34.  
  35.   let startingMerit = 1000
  36.   // finding the rank at the day of merit system introduction
  37.  for (let i = 0;i<k.length;i++){
  38.   if (a<k[i]){
  39.     startingMerit = startMerits[activityRequirements[k[i-1]]]
  40.     break;
  41.   }
  42.   }
  43.  
  44.   const earnedMerit = rawMerit - startingMerit
  45.  
  46.   return earnedMerit
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top