Skip to content

Instantly share code, notes, and snippets.

@mitchallen
Created January 11, 2022 09:15
Show Gist options
  • Select an option

  • Save mitchallen/f0d8a563fcd209ec9fa8206822b3f9c8 to your computer and use it in GitHub Desktop.

Select an option

Save mitchallen/f0d8a563fcd209ec9fa8206822b3f9c8 to your computer and use it in GitHub Desktop.
// 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