diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 23:46:16 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 23:46:16 -0400 |
commit | 31307362fac9a6d75a373463495aa688cfbc3cd1 (patch) | |
tree | 407227eea9ed4d967b5547941c14d264e7028204 | |
parent | de517d06737f77a0cfc818c159b388b4e0c4d6b1 (diff) |
Define and use the pool function
-rw-r--r-- | __tests__/dice.test.js | 4 | ||||
-rw-r--r-- | src/dice.js | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js index 4828ce4..83b8a9d 100644 --- a/__tests__/dice.test.js +++ b/__tests__/dice.test.js @@ -1,4 +1,4 @@ -const { constant, d, add, subtract } = require('../src/dice.js') +const { pool, constant, d, add, subtract } = require('../src/dice.js') const defaultNumberRolls = 500 const defaultError = 0.2 @@ -72,7 +72,7 @@ const rollForTest = (die, numberRolls) => { let rolls = [] for (let i = 0; i < numberRolls; i++) { - let rolled = die() + let rolled = pool(die) pools.push(rolled) rolls.push(rolled.reduce(plus)) } diff --git a/src/dice.js b/src/dice.js index c8a2572..5edc892 100644 --- a/src/dice.js +++ b/src/dice.js @@ -1,7 +1,11 @@ const constant = n => () => [n] +const pool = (die) => { + return die() +} + const roll = (die) => { - return die().reduce((a, b) => (a + b)) + return pool(die).reduce((a, b) => (a + b)) } const d = (number, sides) => { @@ -37,8 +41,10 @@ const subtract = (die1, die2) => { } } +exports.pool = pool +exports.roll = roll exports.constant = constant exports.d = d exports.add = add exports.subtract = subtract -exports.roll = roll +exports.negative = negative |