Last active
January 16, 2019 22:11
-
-
Save Tiramisu77/155f1e076c58728efc06131c7226baee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calculateEarnedMerit = function(activity, rawMerit){ | |
const meritStartDate = new Date("January 24, 2018") | |
const today = Date.now() | |
const startMerits = { | |
"Brand new": 0, | |
"Newbie":0, | |
"Jr Member": 1, | |
"Member": 10, | |
"Full Member": 100, | |
"Sr. Member": 250, | |
"Hero Member": 500, | |
"Legendary": 1000 | |
} | |
const activityRequirements = { | |
0: "Brand new", | |
1: "Newbie", | |
30: "Jr Member", | |
60: "Member", | |
120: "Full Member", | |
240: "Sr. Member", | |
480: "Hero Member", | |
//average activity of freshly ranked-up Legendary | |
902: "Legendary" | |
} | |
//activity at the day of merit system introduction | |
//assuming that activity is maxed out between today and meritStartDate | |
let a = Math.max(activity - Math.floor((today - meritStartDate)/(1000*60*60*24)),0) | |
const k = Object.keys(activityRequirements) | |
let startingMerit = 1000 | |
// finding the rank at the day of merit system introduction | |
for (let i = 0;i<k.length;i++){ | |
if (a<k[i]){ | |
startingMerit = startMerits[activityRequirements[k[i-1]]] | |
break; | |
} | |
} | |
const earnedMerit = rawMerit - startingMerit | |
return earnedMerit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment