From 3fccdd3d61d96d3c979f72c7a9d9c26420ae3656 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 19 Jul 2017 23:13:21 -0400 Subject: Implement exploding dice --- src/dice.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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 + }) } } -- cgit v1.2.3