m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/dice.js b/src/dice.js
index 213eda8..b60af68 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -43,7 +43,16 @@ const subtract = (die1, die2) => {
const explode = (die1, die2) => {
return () => {
- return die1()
+ const explodeOn = roll(die1)
+ return die2().map(die => () => {
+ let lastRoll = die()
+ let total = lastRoll
+ while (lastRoll >= explodeOn) {
+ lastRoll = die()
+ total += lastRoll
+ }
+ return total
+ })
}
}