From 3a5f09ac15642bbebf7351ec92ad2bee7f0b0acc Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 19 Jul 2017 22:43:45 -0400 Subject: Change internal dice implementation - Previously calling a die returned an array of numbers. - Now calling a die returns an array of functions, each of which returns a number when called. --- src/dice.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/dice.js b/src/dice.js index cbc7325..213eda8 100644 --- a/src/dice.js +++ b/src/dice.js @@ -1,7 +1,7 @@ -const constant = n => () => [n] +const constant = n => () => [() => n] const pool = (die) => { - return die() + return die().map((d) => d()) } const roll = (die) => { @@ -16,7 +16,7 @@ const d = (number, sides) => { const currentSides = roll(sides) for (let i = 0; i < currentNumber; i++) { - pool.push(1 + Math.floor(Math.random() * currentSides)) + pool.push(() => (1 + Math.floor(Math.random() * currentSides))) } return pool @@ -31,7 +31,7 @@ const add = (die1, die2) => { const negative = (die) => { return () => { - return die().map(value => -value) + return die().map(die => () => (-die())) } } -- cgit v1.2.3