m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__tests__/dice.test.js4
-rw-r--r--src/dice.js10
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