Created
January 9, 2022 10:41
-
-
Save mitchallen/7b7413bbd1dc00ea05bbe3af4fd78c5b to your computer and use it in GitHub Desktop.
A file to test the coinflip.js module
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-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(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: https://scriptable.com/blog/how-to-create-a-javascript-random-boolean-function-nodejs-browser