m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-10 15:18:11 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-10 15:18:45 -0400
commit7af1277c30d4942bd109e03c1991d81eb89b49fc (patch)
tree8c88f55fb90fa3f45f707295e76efb0ee54491ee /src
parentcbfed7099a748c586d984611e9b46ecc55ea3b68 (diff)
Implement dice subtraction
Diffstat (limited to 'src')
-rw-r--r--src/dice.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index bc75cb7..c45bafc 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -16,10 +16,23 @@ const add = (die1, die2) => {
}
}
+const negative = (die) => {
+ return () => {
+ return die().map(value => -value)
+ }
+}
+
+const subtract = (die1, die2) => {
+ return () => {
+ return die1().concat(negative(die2)())
+ }
+}
+
const roll = (die) => {
return die().reduce((a, b) => (a + b))
}
exports.d = d
exports.add = add
+exports.subtract = subtract
exports.roll = roll