m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-11 12:18:10 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-11 12:19:07 -0400
commit69b48d1a9c4e97d5f71230c75b3cfe6d8453558f (patch)
tree5397c84f16bc2343bed4badf39b8ac47189856f4 /src
parent11219fcba6108f7f8db138ae8a3cbb0ec8f4df3b (diff)
Add the constant die
Diffstat (limited to 'src')
-rw-r--r--src/dice.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/dice.js b/src/dice.js
index c45bafc..ead3d16 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -1,9 +1,14 @@
+const constant = n => () => [n]
+
const d = (number, sides) => {
return () => {
let pool = []
- for (let i = 0; i < number; i++) {
- pool.push(1 + Math.floor(Math.random() * sides))
+ const currentNumber = number()
+ const currentSides = sides()
+
+ for (let i = 0; i < currentNumber; i++) {
+ pool.push(1 + Math.floor(Math.random() * currentSides))
}
return pool
@@ -32,6 +37,7 @@ const roll = (die) => {
return die().reduce((a, b) => (a + b))
}
+exports.constant = constant
exports.d = d
exports.add = add
exports.subtract = subtract