Last active
August 29, 2015 13:59
-
-
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.
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
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