m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-09 16:32:02 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-09 16:33:50 -0400
commit606a177f0d0fd03fb8ac8899e67c0d4083b93ba6 (patch)
treedf15a1bb24e1eaaac6f4798ebc64e3085f57b2e8 /src
parentc97eb5f531678c358c65d5e2738d5e6ca6c09b66 (diff)
Implement basic dice
Diffstat (limited to 'src')
-rw-r--r--src/dice.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
new file mode 100644
index 0000000..2914317
--- /dev/null
+++ b/src/dice.js
@@ -0,0 +1,18 @@
+const d = (number, sides) => {
+ return () => {
+ let pool = []
+
+ for (let i = 0; i < number; i++) {
+ pool.push(1 + Math.floor(Math.random() * sides))
+ }
+
+ return pool
+ }
+}
+
+const roll = (die) => {
+ return die().reduce((a, b) => (a + b))
+}
+
+exports.d = d
+exports.roll = roll