Created
October 21, 2011 21:12
-
-
Save jhuttner/1304991 to your computer and use it in GitHub Desktop.
eachWhile
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 add_to_list = false; | |
var result = []; | |
$.each(checks, function(check) { | |
// don't go through all the logic if we know we are going to append it | |
if (add_to_list) { | |
return true; | |
} | |
if (check()) { | |
addToList = true; | |
} | |
}); | |
if (add_to_list) { | |
result.push(item); | |
} | |
/// BECOMES | |
var add_to_list = false; | |
var result = []; | |
$.eachWhile(!add_to_list, checks, function(check) { | |
if (check()) { | |
addToList = true; | |
} | |
}); | |
if (add_to_list) { | |
result.push(item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment