Skip to content

Instantly share code, notes, and snippets.

@mitchallen
Created January 9, 2022 10:41
Show Gist options
  • Select an option

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

Select an option

Save mitchallen/7b7413bbd1dc00ea05bbe3af4fd78c5b to your computer and use it in GitHub Desktop.
A file to test the coinflip.js module
// Author: Mitch Allen
// File: test-coinflip.js
import {coinFlip} from './coinflip.js';
// define test function for coinFlip()
function testCoinFlip() {
// define the number of coin flips to generate
const LIMIT = 100;
// create an array filled with coin flip results
let arr = Array.from({length: LIMIT}, () => coinFlip());
// log the generated coin flips
console.log(arr);
// count the occurences of 1s and 0s
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 coinFlip()
testCoinFlip();
@mitchallen
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment