diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-30 18:27:55 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-30 18:27:55 -0400 |
commit | 13e482fefb3090645a941a643c73eadcbf0a1a34 (patch) | |
tree | 33e6da05d96eff09c36fbede4af9ad002fa7c400 /src | |
parent | 5087cde4825d91112cad565c68d81296359cf4d8 (diff) |
Implement division
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 7 | ||||
-rw-r--r-- | src/lexer.js | 1 | ||||
-rw-r--r-- | src/parser.js | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js index abe3c4b..d47455e 100644 --- a/src/dice.js +++ b/src/dice.js @@ -50,6 +50,12 @@ const multiply = (die1, die2) => { } } +const divide = (die1, die2) => { + return () => { + return [() => Math.floor(roll(die1) / roll(die2))] + } +} + const bonusAdd = (die1, die2) => { return () => { return die1().map(die => { @@ -194,6 +200,7 @@ exports.d = d exports.add = add exports.subtract = subtract exports.multiply = multiply +exports.divide = divide exports.bonusAdd = bonusAdd exports.bonusSubtract = bonusSubtract exports.negative = negative diff --git a/src/lexer.js b/src/lexer.js index c3eec8a..59fba16 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -19,6 +19,7 @@ newLexemeType('d', 'd') newLexemeType('bigPlus', ' \\+ ' ) newLexemeType('bigMinus', ' - ') newLexemeType('bigTimes', ' \\* ') +newLexemeType('bigDivide', ' / ') newLexemeType('plus', '\\+') newLexemeType('minus', '-') newLexemeType('(', '\\(') diff --git a/src/parser.js b/src/parser.js index 1a1e5d4..fd0fd59 100644 --- a/src/parser.js +++ b/src/parser.js @@ -72,6 +72,7 @@ newDieOperation('t') newInfix('bigPlus', 20, { type: 'add' }) newInfix('bigMinus', 20, { type: 'subtract' }) newInfix('bigTimes', 23, { type: 'multiply' }) +newInfix('bigDivide', 23, { type: 'divide' }) newInfix('plus', 25, { type: 'bonusAdd' }) newInfix('minus', 25, { type: 'bonusSubtract' }) newSymbol('minus', (parser) => { |