Created
October 18, 2011 05:32
-
-
Save jgable/1294683 to your computer and use it in GitHub Desktop.
Modern Web Development Blog Post code - jQuery Gems
This file contains hidden or 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 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"); } });