m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-19 22:43:45 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-19 23:38:40 -0400
commit3a5f09ac15642bbebf7351ec92ad2bee7f0b0acc (patch)
treed7d3f4b14efe2723a39b05130d23abd25b193993 /src
parentba07c4d236d2a03f5f7647cf4e724f853703172f (diff)
Change internal dice implementation
- Previously calling a die returned an array of numbers. - Now calling a die returns an array of functions, each of which returns a number when called.
Diffstat (limited to 'src')
-rw-r--r--src/dice.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/dice.js b/src/dice.js
index cbc7325..213eda8 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -1,7 +1,7 @@
-const constant = n => () => [n]
+const constant = n => () => [() => n]
const pool = (die) => {
- return die()
+ return die().map((d) => d())
}
const roll = (die) => {
@@ -16,7 +16,7 @@ const d = (number, sides) => {
const currentSides = roll(sides)
for (let i = 0; i < currentNumber; i++) {
- pool.push(1 + Math.floor(Math.random() * currentSides))
+ pool.push(() => (1 + Math.floor(Math.random() * currentSides)))
}
return pool
@@ -31,7 +31,7 @@ const add = (die1, die2) => {
const negative = (die) => {
return () => {
- return die().map(value => -value)
+ return die().map(die => () => (-die()))
}
}