Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Last active August 29, 2015 14:03
Show Gist options
  • Save jasonrhodes/09ad69bff317544aefbd to your computer and use it in GitHub Desktop.
Save jasonrhodes/09ad69bff317544aefbd to your computer and use it in GitHub Desktop.
Creates a new function that will only run {{max}} number of times and then the function becomes a no-op pass-through
/**
* Creates a new function that will only run
* max number of times and then the function
* will become a no-op pass-through
*
* This could probably become its own little lib
*
* @param function func The main function
* @param int max
* @param int count optional starting point
*
* @return function
*/
function times(func, max, count) {
count = count || 0;
return function () {
if (count < max) {
count += 1;
return func.apply(this, arguments);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment