m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/dice.js
blob: bc75cb769b89ba7ca4a4890df1867630de608f83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 add = (die1, die2) => {
  return () => {
    return die1().concat(die2())
  }
}

const roll = (die) => {
  return die().reduce((a, b) => (a + b))
}

exports.d = d
exports.add = add
exports.roll = roll