Created
July 15, 2015 21:22
-
-
Save webbower/d3f0036f2f66b69abab5 to your computer and use it in GitHub Desktop.
Safe loop wrapper
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
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