diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 18 |
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 |