Skip to content

Instantly share code, notes, and snippets.

@chrisjensen
Last active June 16, 2020 09:38
Show Gist options
  • Save chrisjensen/6855511edcc7b1eac8b6383ea922ddf2 to your computer and use it in GitHub Desktop.
Save chrisjensen/6855511edcc7b1eac8b6383ea922ddf2 to your computer and use it in GitHub Desktop.
Calculate split donations
// 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