From fd42ead81b823f997384db7f8e126bce68064884 Mon Sep 17 00:00:00 2001 From: bertieb Date: Sat, 6 Feb 2021 16:49:03 +0000 Subject: [PATCH] Remove unnecessary constructor(), add print line --- dice.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/dice.ts b/dice.ts index 9cfb810..d0f9c31 100644 --- a/dice.ts +++ b/dice.ts @@ -51,7 +51,15 @@ class D10 implements Dice { sides: number = 10; type: string = "d10" - constructor() { + roll(numberToRoll: number): DiceResult { + let results: DiceResult = { total: 0, dice: [] }; + for (let i = 0; i < numberToRoll; i++) { + results.dice.push(randIntMinOne(this.sides)); + } + + results.total = results.dice.reduce((acc: number, curr: number) => acc + curr); + + return results; } [util.inspect.custom](): string { @@ -71,16 +79,6 @@ class D10 implements Dice { * { total: 16, dice [ 3, 5, 6, 2] } * */ - roll(numberToRoll: number): DiceResult { - let results: DiceResult = { total: 0, dice: [] }; - for (let i = 0; i < numberToRoll; i++) { - results.dice.push(randIntMinOne(this.sides)); - } - - results.total = results.dice.reduce((acc: number, curr: number) => acc + curr); - - return results; - } } class Asphodice extends D10 { @@ -292,6 +290,7 @@ class Asphodice extends D10 { let asphodice: Asphodice = new Asphodice(); let number: number = 4; for (let i = 0; i < 10; i++) { + console.log("--------------------"); console.log("Rolling", number, asphodice); console.log(asphodice.roll(4)); }