-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbf53d9
commit f532c2c
Showing
4 changed files
with
24 additions
and
53 deletions.
There are no files selected for viewing
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
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
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
12 changes: 6 additions & 6 deletions
12
src/utils/calculateMultiplerCost.ts → src/utils/calculateMultiplierCost.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
const addMultiplier = ( | ||
cost: number, | ||
currentQuantity: number, | ||
multipler: number | ||
) => Math.floor(cost * multipler ** currentQuantity) | ||
multiplier: number | ||
) => Math.floor(cost * multiplier ** currentQuantity) | ||
|
||
const calculateMultiplerCost = ( | ||
const calculateMultiplierCost = ( | ||
cost: number, | ||
currentQuantity: number, | ||
multipler: number, | ||
multiplier: number, | ||
purchaseQuantity: number | ||
) => { | ||
const quantities = [...Array(purchaseQuantity).keys()].map(item => { | ||
const tempQuantity = item + currentQuantity | ||
|
||
return tempQuantity === 0 | ||
? cost | ||
: addMultiplier(cost, tempQuantity, multipler) | ||
: addMultiplier(cost, tempQuantity, multiplier) | ||
}) | ||
return quantities.reduce((total, amount) => total + amount) | ||
} | ||
|
||
export default calculateMultiplerCost | ||
export default calculateMultiplierCost |