I have a function that changes an object for me and I'm wondering how a bit of it works and would be grateful if someone could explain it or point me in the right direction. Here is the function:
$scope.filteredObject = Object.keys($scope.filterObject).reduce(function(p, collection) {
var values = $scope.filterObject[collection];
p[collection] = Object.keys(values).filter(function(key) {
return values[key] === true;
}).map(function(key) {
return key;
});
return p;
}, {});
So this works great, but I'm wondering what the }, {}); at the end of the function does exactly. Im not exactly sure the name of that and googleing "}, {} after a function in javascript" seems to confuse the hell out of google (lol). Thanks!
.reduce(function(p, collection) { ... }, {});In other words, the rest of the.reduce()function call.{}) are parameters to thereducefunction.