Created
June 21, 2011 16:35
-
-
Save dpritchett/1038260 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
game_log = new Array(); | |
go = function (){ | |
x = Math.floor(Math.random() * 11) + Math.floor(Math.random() * 11); | |
return x; | |
}; | |
execute_n_times = function(n) { | |
for( i = 0; i < n; i++){ | |
single_roll = go(); | |
if(game_log[single_roll] == undefined){ | |
game_log[single_roll] = 0;} | |
game_log[single_roll]++;}}; | |
print_test_results = function() { | |
for(i = 0; i < game_log.length; i++){ | |
console.log(i + ":\t" + game_log[i]);}}; | |
calculate_winner = function (game_log) { | |
has_most = -1; | |
the_most = 0; | |
for(i = 0; i < game_log.length; i++){ | |
if(game_log[i] > the_most){ | |
has_most = i; | |
the_most = game_log[has_most]}} | |
return has_most;}; | |
run_n_times_with_report = function (n) { | |
execute_n_times(n); | |
print_test_results(); | |
console.log("\nWINNER: " + calculate_winner(game_log));}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment