This module has several functions used for aggregating and sorting collections of data
Returns the first element in an array
the array
the first element of the array
Maps and reduces an array of data into an array of groups.
This is an advanced function for doing aggregate calculations on an array of data objects.
The mapping parameter, which can be either a function, an array of keys, or an object of keys and functions, is used to map the data objects into groups by a key.
The next step is to process these groups through an optional reducer, which can aggregate data or add values, etc.
the function, array, or object with key-value pairs where the key is a property shared amongst the data in the array, and the value is a function that will be applied to this value for each object.
the object containing functions mapped to keys in our newly created group (The keys in the group are the value of all the properties for each data, but stored in an array. Performing a reduction on these properties, leaves just a property and a new reduced value (like a sum or average, for instance). Each function in the reduction object is passed the group by key it will be working on.
returns an array of groups
var people = [];
people.push({firstname: "John", lastname:"Smith"});
people.push({firstname: "Matt", lastname:"Smith"});
people.push({firstname: "Mike", lastname:"Doe"});
var groups = thinkmap.data.group(people,["lastname"]);
var people = [];
people.push({firstname: "John", lastname:"Smith"});
people.push({firstname: "Matt", lastname:"Smith"});
people.push({firstname: "Mike", lastname:"Doe"});
var groups = thinkmap.data.group(people,["lastname"],{
"firstname": function(group){ //Reducer object
return group.join(',');
}
});
Returns the last element in an array
the array
the last element of the array