m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-11 16:22:45 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-11 16:28:54 -0400
commitcd0feb6ffd0795ac375a20bb89b00d080d07d858 (patch)
tree584e629106ea36d8aaebfe926ada8db5fb074e2b
parent26de1b9f0646bdd495a9457923a8146120704f1a (diff)
Format large pools correctlyHEADmaster
-rwxr-xr-xbin/dicebag.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/bin/dicebag.js b/bin/dicebag.js
index 6e88ae6..be0a850 100755
--- a/bin/dicebag.js
+++ b/bin/dicebag.js
@@ -3,17 +3,35 @@
const { parse, roll, pool } = require('../index.js')
+const rollRoller = {
+ roll: roll,
+ format: value => value
+}
+
+const poolRoller = {
+ roll: pool,
+ format: values => {
+ if (values.length === 0) {
+ return '[]'
+ } else {
+ return '[ ' + values.reduce((acc, next) => (
+ acc + ', ' + String(next)
+ )) + ' ]'
+ }
+ }
+}
+
const parseArgs = () => {
const args = process.argv.slice(2)
const parsedArgs = {
- roller: roll,
+ roller: rollRoller,
expression: null
}
while (args.length > 0) {
const arg = args.shift()
if (arg === '-p') {
- parsedArgs.roller = pool
+ parsedArgs.roller = poolRoller
} else {
parsedArgs.expression = arg
}
@@ -25,7 +43,8 @@ const parseArgs = () => {
const rollDie = (string, roller) => {
try {
const die = parse(string)
- console.log(roller(die))
+ const roll = roller.roll(die)
+ console.log(roller.format(roll))
} catch (error) {
console.log(error.message)
}