From 7af1277c30d4942bd109e03c1991d81eb89b49fc Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 10 Jul 2017 15:18:11 -0400 Subject: Implement dice subtraction --- src/dice.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') 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 -- cgit v1.2.3