Skip to content

Instantly share code, notes, and snippets.

@stevelippert
Created February 27, 2015 16:21
Show Gist options
  • Save stevelippert/8c423d0ddb88e35c6ae8 to your computer and use it in GitHub Desktop.
Save stevelippert/8c423d0ddb88e35c6ae8 to your computer and use it in GitHub Desktop.
An example of bad code to count the number of matching elements on a page.
function countFlaggedQs(){
var fgC = 0,
fgT = ' flagged questions';
$(".q-flag").each(function(){
if( $(this).children(".icon-flag").length ) {
fgC++;
}
});
fgT = (fgC === 1) ? ' flagged question' : ' flagged questions';
$("#q_fg").html( fgC+' <i class="icon-flag" title="'+fgC+fgT+'"></i>' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment