Querying Accounting Data
Overview
Categorizing and Querying Categorical Data
Once we have a tree of sales people and managers, we can now easily query the data for information that we
desire. For instance, consider a set of sales data, such as the follwoing:
Next, we can use the standard array function, filter, to get a list of all the sales that attributable to gary.
In addition, we use the treemap created above to filter for all sales that roll up to jane as the sales manager.
let garySales = sales.filter(p=>p.name === 'gary');
let janeSales = sales.filter(p=>{
let salesperson = treemap[p.name];
if(salesperson.ancestors["jane"] !== undefined) return true;
return false;
});
Try it!