Skip to content

Instantly share code, notes, and snippets.

@safareli
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safareli/10509116 to your computer and use it in GitHub Desktop.
Save safareli/10509116 to your computer and use it in GitHub Desktop.
javascript times function I made when working on testing random numbers, but can be used anywhere.
var timesGen = function(t,useArguments){
return function(callback,thisArg){
thisArg = thisArg || null;
return function(){
for(var i = 0;i < t; i++){
callback.apply(thisArg,(useArguments) ? arguments : [i]);
}
}
}
};
//example without caller arguments
var times = timesGen(100,false);
it('should do something', times(function(i){
console.log(i);
}))
//example with caller arguuments
var times = timesGen(100,true);
it('should do something', times(function(done){
async(function(){
console.log('ok');
done()
})
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment