Skip to content

Instantly share code, notes, and snippets.

@soopercorp
Created April 2, 2012 20:00
Show Gist options
  • Save soopercorp/2286836 to your computer and use it in GitHub Desktop.
Save soopercorp/2286836 to your computer and use it in GitHub Desktop.
cd-solution
/*
Task:
Fill the array ‘randomNumbers’ with 64 random numbers.
Make sure that there are no duplicate numbers in the array.
*/
// You can’t change this function
function getRandomNumber(callback) {
var random = Math.floor( Math.random() * 128 );
return setTimeout( function(){ callback(random); }, 1000);
}
var randomNumbers = [];
// Start your code below here
// -----------------------------------
var ct = 0;
function rand(number) {
if(ct==64)
return;
if(randomNumbers.indexOf(number) == -1) {
randomNumbers.push(number);
ct++;
}
}
setInterval(getRandomNumber,0,rand);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment