blob: 1587eef1fb042b4fc21991b54352d0993878e428 (
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
const constant = n => () => [n]
const pool = (die) => {
return die()
}
const roll = (die) => {
return pool(die).reduce((a, b) => (a + b), 0)
}
const d = (number, sides) => {
return () => {
let pool = []
const currentNumber = roll(number)
const currentSides = roll(sides)
for (let i = 0; i < currentNumber; i++) {
pool.push(1 + Math.floor(Math.random() * currentSides))
}
return pool
}
}
const add = (die1, die2) => {
return () => {
return die1().concat(die2())
}
}
const negative = (die) => {
return () => {
return die().map(value => -value)
}
}
const subtract = (die1, die2) => {
return () => {
return die1().concat(negative(die2)())
}
}
exports.pool = pool
exports.roll = roll
exports.constant = constant
exports.d = d
exports.add = add
exports.subtract = subtract
exports.negative = negative
|