Guest User

Untitled

a guest
Mar 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. var Recurrence = ( function( document, window ) {
  2.  
  3. function recurrence() {
  4. console.info( 'Probable.run(sample_size: e.g. 1000)');
  5. };
  6.  
  7. recurrence.prototype.run = function( sample_size = 1000 ) {
  8. var sample_array = [];
  9. var sample_array_unique = [];
  10. for ( var sample_index = 0; sample_index < sample_size; sample_index++ ) {
  11. var random_number = Math.floor((Math.random() * sample_size) + 1);
  12. sample_array.push(random_number);
  13. if ( sample_array_unique.indexOf(random_number) === -1 ) {
  14. sample_array_unique.push(random_number);
  15. }
  16. console.info( sample_index, sample_array_unique.length / sample_array.length * 100, sample_array, sample_array_unique );
  17. // console.info( sample_index, this.unique( sample_array ).length / sample_array.length * 100, sample_array, sample_array_unique );
  18. }
  19. console.log( sample_array_unique.length / sample_array.length * 100 );
  20. // console.log( this.unique( sample_array ).length / sample_array.length * 100 );
  21. };
  22.  
  23. recurrence.prototype.unique = function( array ) {
  24. return array.filter( unique );
  25. }
  26.  
  27. function unique( value, index, self ) {
  28. return self.indexOf(value) === index;
  29. };
  30.  
  31. return recurrence;
  32.  
  33. } )( document, window );
  34.  
  35. var recurrence = new Recurrence();
Add Comment
Please, Sign In to add comment