m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/dice.js
blob: 2914317e670bec034807fe0c6654d1446225cb5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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