This file contains 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
(function() { | |
var a = [2, 5, 8, 42, 12]; | |
var x; | |
// x = _.find(a, function(num) { | |
// return num > 5; | |
// }); | |
x = _.filter(a, function(num) { | |
return num > 5; |
This file contains 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
(function() { | |
// _.each([2, 5, 8], function(num) { | |
// console.log(num * 2); | |
// }); | |
var x = _.map([2, 5, 8], function(num) { | |
return num * 2; | |
}); | |
console.log(x); | |
})(); |
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Underscore</title> | |
<script src="underscore-min.js"></script> | |
</head> | |
<body> |
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Underscore</title> | |
<script src="underscore-min.js"></script> | |
</head> | |
<body> |
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Underscore</title> | |
<script src="underscore-min.js"></script> | |
</head> | |
<body> |
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Underscore</title> | |
<script src="underscore-min.js"></script> | |
</head> | |
<body> |
This file contains 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
(function() { | |
var x; | |
x = _.shuffle([2, 8, 10, 3]); | |
//x = _([2, 8, 10, 3]).shuffle(); | |
console.log(x); | |
})(); |
This file contains 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
(function() { | |
var a = [1, 2, 5, 8, 42, 12]; | |
var x; | |
x = _.groupBy(a, function(num) { | |
return num % 3; | |
}); | |
x = _.countBy(a, function(num) { | |
return num % 2 == 0 ? 'even' : 'odd'; |
This file contains 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
(function() { | |
// Model | |
var Task = Backbone.Model.extend({ | |
defaults: { | |
title: 'do something!', | |
completed: false | |
} | |
}); | |
var task1 = new Task({ |
This file contains 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
(function() { | |
// Model | |
var Task = Backbone.Model.extend({ | |
defaults: { | |
title: 'do something!', | |
completed: false | |
}, | |
validate: function(attrs) { | |
if (_.isEmpty(attrs.title)) { | |
return "title must not be empty!"; |