m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/dice.js
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-02 00:47:46 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-02 01:02:16 -0400
commit1cc6b80cfd4875f289837421cdbe81e3dfcf0ed1 (patch)
tree0fb04bc04f27620f6def5dc310953a637e22ae07 /src/dice.js
parent650f7d82197cba35df3654abf548e07e213c1b14 (diff)
Implement repeat
Diffstat (limited to 'src/dice.js')
-rw-r--r--src/dice.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index d47455e..5a484b0 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -193,6 +193,19 @@ const thresholdLow = (die1, die2) => {
return threshold(lessThanOrEqual, die1, die2)
}
+const repeat = (die1, die2) => {
+ return () => {
+ const times = roll(die2)
+
+ let results = []
+ for (let i = 0; i < times; i++) {
+ results = results.concat(die1())
+ }
+
+ return results
+ }
+}
+
exports.pool = pool
exports.roll = roll
exports.constant = constant
@@ -212,3 +225,4 @@ exports.againAbove = againAbove
exports.againUnder = againUnder
exports.thresholdHigh = thresholdHigh
exports.thresholdLow = thresholdLow
+exports.repeat = repeat