Created
June 17, 2016 20:25
-
-
Save JeremyIglehart/0303f987296d1509d93e92b19f02f86e to your computer and use it in GitHub Desktop.
A function which tests the distribution of _.sample()
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
// Option 1 | |
(function(arraySize = 10, timesToRun = 1000){ | |
let myArray = Array.apply(null, {length: arraySize}).map(Number.call, Number); | |
let resultsArray = Array.apply(null, Array(arraySize)).map(Number.prototype.valueOf,0); | |
for (let i = 0; i < timesToRun; i++) { | |
var result = _.sample(myArray); | |
resultsArray[result]++; | |
} | |
return resultsArray; | |
})(/*10, 1000*/); | |
// Option 2 | |
(function(arraySize = 10, timesToRun = 1000){ | |
let myArray = (new Array(arraySize)).map(Number.call, Number); | |
let resultsArray = (new Array(arraySize)).fill(0); | |
for (let i = 0; i < timesToRun; i++) { | |
var result = _.sample(myArray); | |
resultsArray[result]++; | |
} | |
return resultsArray; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment