Created
June 13, 2018 05:51
-
-
Save niinpatel/6c845abd23e283266a37032ae9b703eb to your computer and use it in GitHub Desktop.
This file contains 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
function playMontyHall(toSwitch) { | |
let carIsIn = Math.floor(Math.random() * 3); | |
let doorSelected = Math.floor(Math.random() * 3); | |
let revealedDoor = [0,1,2].find((door) => door !== carIsIn && door !== doorSelected); | |
if(toSwitch){ | |
return carIsIn === [0,1,2].find((door) => door !== doorSelected && door !== revealedDoor) | |
} | |
else { | |
return carIsIn === doorSelected | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment