Skip to content

Instantly share code, notes, and snippets.

@webbower
Created July 15, 2015 21:22
Show Gist options
  • Save webbower/d3f0036f2f66b69abab5 to your computer and use it in GitHub Desktop.
Save webbower/d3f0036f2f66b69abab5 to your computer and use it in GitHub Desktop.
Safe loop wrapper
function safeLoop(max) {
max = (+max) || 100;
// Track how many times the function has been called
var ctr = 1;
return function(cmp) {
// Loop count test and increment counter. If we’re under the max and the live comparison is truthy, return the live comparison
if ((ctr++) > max) return false;
// Otherwise, return the comparison
else return cmp;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment