Skip to content

Instantly share code, notes, and snippets.

@aakashbapna
Created April 24, 2014 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakashbapna/11250140 to your computer and use it in GitHub Desktop.
Save aakashbapna/11250140 to your computer and use it in GitHub Desktop.
<!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>
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