Skip to content

Instantly share code, notes, and snippets.

@jgable
Created October 18, 2011 05:32
Show Gist options
  • Save jgable/1294683 to your computer and use it in GitHub Desktop.
Save jgable/1294683 to your computer and use it in GitHub Desktop.
Modern Web Development Blog Post code - jQuery Gems
var nums = [1,2,3,4,5,6,7,8,9,10];
// $.each is a simple foreach helper
$.each(nums, function() { if(this % 2 === 1) { log("Found an odd number"); });
// $.grep is a filter for a list
var odds = $.grep(nums, function() { return this % 2 === 1; });
// $.map is a projection of a list
var labels = $.map(nums, function() { return "Number " + this; });
// $.extend adds or overwrites properties to an existing object.
var defaults = {
modNum: 2
};
var settings = $.extend(defaults, opts);
@iMetro
Copy link

iMetro commented Sep 13, 2012

Seems like an extra } is missing in $.each(nums, function() { if(this % 2 === 1) { log("Found an odd number"); });
like so: $.each(nums, function() { if(this % 2 === 1) { log("Found an odd number"); } });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment