m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/dice.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/dice.js')
-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