Created
January 11, 2022 09:15
-
-
Save mitchallen/f0d8a563fcd209ec9fa8206822b3f9c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Author: Mitch Allen | |
| // File: test-rolldice.js | |
| import { rollDice } from './rolldice.js'; | |
| function testRollDice() { | |
| // create a source list for testing | |
| const source = ['A','B','C','D','E']; | |
| // define the number of dice rolls | |
| const LIMIT = 100; | |
| // create an array filled with dice rolls | |
| let arr = Array.from({length: LIMIT}, () => rollDice( source )); | |
| // log the generated dice rolls | |
| console.log(arr); | |
| // count the occurences of each roll result | |
| let occurrences = arr.reduce((prev, curr) => (prev[curr] = ++prev[curr] || 1, prev), {}); | |
| // log a summary of the occurences | |
| console.log(occurrences); | |
| } | |
| // call test function for rollDice | |
| testRollDice(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment