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-weighted-coinflip.js | |
| import {weightedCoinFlip} from './weighted-coinflip.js'; | |
| // define test function for weightedCoinFlip() | |
| function testWeightedCoinFlip() { | |
| // define the number of weighted coin flips to generate | |
| const LIMIT = 100; |
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: weighted-coinflip.js | |
| // weightedCoinFlip - return a random 1 or 0 based on weight | |
| export const weightedCoinFlip = (weight) => Math.random() <= weight; |
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: app.js | |
| import { coinFlip } from './coinflip.js'; | |
| let canvas = document.getElementById("canvas"); | |
| const SCREEN_SIZE = 300; | |
| const DIM = 10; | |
| const CELL_SIZE = SCREEN_SIZE / DIM; | |
| const BORDER = 1; |
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: app.css | |
| */ | |
| canvas { | |
| padding: 0; | |
| margin: auto; | |
| display: block; | |
| width: 400px; |
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
| <html> | |
| <head> | |
| <title>js-coinFlip-01</title> | |
| <link rel="stylesheet" href="./app.css"> | |
| </head> | |
| <body> | |
| <canvas id="canvas" width="300" height="300" /> | |
| <script type="module" src="./app.js"> |
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; |
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: coinflip.js | |
| // coinFlip - return a random 1 or 0 | |
| export const coinFlip = () => Math.round(Math.random()); |
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: js-set.js | |
| const X_SIZE = 100; | |
| let a = [...Array(X_SIZE)].map(() => Math.random().toFixed(2)); | |
| let set = new Set(a); | |
| console.log(a.length); |
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: pickone.js | |
| let pickOne = (list) => list[Math.floor(Math.random() * list.length)] | |
| let LIMIT = 5; | |
| let list = [...Array(LIMIT)].map(() => Math.random()); | |
| console.log(list); |
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 | |
| // coinflip.js | |
| let coinFlip = () => Math.round(Math.random()); | |
| const LIMIT = 100; | |
| let list = [...Array(LIMIT)].map(() => coinFlip() ? "HEADS" : "TAILS"); | |
| const occurrences = list.reduce(function (acc, curr) { |