Skip to content

Instantly share code, notes, and snippets.

@mvcds
Last active August 16, 2021 19:05
Show Gist options
  • Save mvcds/42ec8a628223cd73ed659c4a40a235d1 to your computer and use it in GitHub Desktop.
Save mvcds/42ec8a628223cd73ed659c4a40a235d1 to your computer and use it in GitHub Desktop.
Testing data or rules 2
// this is hard-coded data
// probably it comes from the business rules
const MIN_POINTS = 5
// the argument is a dynamic data
// it might come from another place on the codebase
// or somewhere else, like a database
function calculateFidelity({ type, experiments }: User, products: [Product]) {
const points = products.reduce(
(total,{ fidelityPoints }) => total + fidelityPoints,
MIN_POINTS
)
if (experiments.includes(INCREASE_FIDELITY_GAMA)) {
points *= 3
}
//in js/ts we don't know if `type.fidelity` is a data or a rule (getter)
return type.fidelityModifier * points
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment