Skip to content

Instantly share code, notes, and snippets.

@jhuttner
Created October 21, 2011 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhuttner/1304991 to your computer and use it in GitHub Desktop.
Save jhuttner/1304991 to your computer and use it in GitHub Desktop.
eachWhile
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