m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-15 17:49:49 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-15 17:50:09 -0400
commitd939daae10c15b00652bf87625d87ad2eed1ce39 (patch)
tree0e1538e11322816dc8927f46df5ddc0482fec6da
parentab75ff5d633f1c85b3ac7496e9d22809f461483d (diff)
Handle 0 dice
-rw-r--r--__tests__/dice.test.js5
-rw-r--r--src/dice.js2
2 files changed, 4 insertions, 3 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js
index 5d3fac1..9f3106e 100644
--- a/__tests__/dice.test.js
+++ b/__tests__/dice.test.js
@@ -40,7 +40,7 @@ expect.extend({
toAllBe(received, expected) {
const pass = received.reduce((allOk, value) => {
return allOk && value === expected
- })
+ }, true)
return {
pass,
@@ -74,7 +74,7 @@ const rollForTest = (die, numberRolls) => {
for (let i = 0; i < numberRolls; i++) {
let rolled = pool(die)
pools.push(rolled)
- rolls.push(rolled.reduce(plus))
+ rolls.push(rolled.reduce(plus, 0))
}
return { pools, rolls }
@@ -263,6 +263,7 @@ describe('constant', () => {
describe('basic dice', () => {
describeBasicDie(1, 6)
+ describeBasicDie(0, 6)
describeBasicDie(2, 8, 500)
describeBasicDie(20, 1)
})
diff --git a/src/dice.js b/src/dice.js
index 5edc892..1587eef 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -5,7 +5,7 @@ const pool = (die) => {
}
const roll = (die) => {
- return pool(die).reduce((a, b) => (a + b))
+ return pool(die).reduce((a, b) => (a + b), 0)
}
const d = (number, sides) => {