m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/dice.js b/src/dice.js
index ead3d16..c8a2572 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -1,11 +1,15 @@
const constant = n => () => [n]
+const roll = (die) => {
+ return die().reduce((a, b) => (a + b))
+}
+
const d = (number, sides) => {
return () => {
let pool = []
- const currentNumber = number()
- const currentSides = sides()
+ const currentNumber = roll(number)
+ const currentSides = roll(sides)
for (let i = 0; i < currentNumber; i++) {
pool.push(1 + Math.floor(Math.random() * currentSides))
@@ -33,10 +37,6 @@ const subtract = (die1, die2) => {
}
}
-const roll = (die) => {
- return die().reduce((a, b) => (a + b))
-}
-
exports.constant = constant
exports.d = d
exports.add = add