Last active
June 16, 2020 09:38
-
-
Save chrisjensen/6855511edcc7b1eac8b6383ea922ddf2 to your computer and use it in GitHub Desktop.
Calculate split donations
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
// Load all charity profiles using the Raisely API | |
const profiles = await getData(api.profiles.getAll()); | |
// Sum the donations to a specific charity | |
const totalSpecific = profiles.reduce( | |
(total, profile) => total + profile.total, | |
0 | |
); | |
// Calculate the general donations by subtracting specific donations from the total of all donations | |
const totalGeneral = | |
get(this.props, "global.campaign.total", 0) - totalSpecific; | |
// Each charity will get an equal split of the general donations | |
let distributedGeneral = totalGeneral / profiles.length; | |
console.log( | |
`Calculating distributed total (${totalGeneral} - ${totalSpecific}) / ${profiles.length}` | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment