Created
April 24, 2014 10:50
-
-
Save aakashbapna/11250140 to your computer and use it in GitHub Desktop.
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> | |
<head> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
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
var utils = { | |
whoami: function() { | |
return this.name; | |
} | |
}; | |
var characters = [ | |
{ 'name': 'barney', 'blocked': true, 'employer': 'slate', age:50 }, | |
{ 'name': 'fred', 'blocked': false, 'employer': 'slate', age:35 }, | |
{ 'name': 'pebbles', 'blocked': true, 'employer': 'na', age:25 } | |
]; | |
/* | |
_.map | |
_.reduce | |
_.filter | |
_.pluck | |
_.mixin | |
_.chain | |
_.template | |
*/ | |
console.clear(); | |
console.log(_.chain(characters) | |
.map(function(obj) { | |
obj.salary = 100000; | |
return obj; | |
}) | |
.filter(function(obj) { | |
if(obj.age < 40) | |
return true; | |
}) | |
.reduce(function(sum, obj) {return sum+obj.salary;}, 0) | |
.value() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment