constincidentsByMonth=d3.group(data,d=>d.dateTime.getMonth()+1);// Group data by month (into map of arrays)
// Iterate through map to get size of each month array (ie. number of incidents)
constincidentCounts=[];
consti=0;
for(leti=1;i<13;i++){
incidentCounts.push(String(incidentsByMonth.get(i).length)+' in month '+(i))
}
returnincidentCounts// It looks as though their was a spike in incidents in May, June and July.
};
// Out of all unique causes, what were the three that occured the most?
{
constcauses=[];
for(letobjofdata){
causes.push(obj.cause)
}
constcounts={};
for(constcofcauses){
counts[c]=counts[c]?counts[c]+1:1;
}
returncounts
// Our top three causes (excluding unspecified) are:
// 1. Driver Inattention/Distraction
// 2. Following Too Closely
// 3. Failure to Yield Right-of-Way
}
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.