Created
May 2, 2014 15:32
-
-
Save navarroaxel/80ea8b5189205f7aca94 to your computer and use it in GitHub Desktop.
Basic Example for underscore use in JavaScript
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
// Option A | |
var threes = _.map([1, 2, 3], function(num){ return num * 3; }); | |
// threes => [3, 6, 9] | |
var odds = _.filter(threes, function(num) { return num % 2 != 0; }); | |
// oddss => [3, 9] | |
// Option B | |
var odds = _.filter(_.map([1, 2, 3], function(num){ return num * 3; }), function(num) { return num % 2 != 0; }); | |
// Option C | |
var odds = _.chain([1, 2, 3]) | |
.map(function(num){ return num * 3; }) | |
.filter(function(num) { return num % 2 != 0; }) | |
.value() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment