Published
Edited
Jun 25, 2020
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
adjust_the_vote = data => {
var sendback = {};
sendback.trump = Math.round(data.trump * rep_turnout);
sendback.clinton = Math.round(data.clinton * dem_turnout);
sendback.st_name = data.st_name;
sendback.fips = data.fips;
sendback.county = data.county;
return sendback;
}
Insert cell
// This will be where we do our fun math later
adjusted_state_counties_vote = _.map(county_vote, item => {
return adjust_the_vote(item);
})
Insert cell
Insert cell
Insert cell
join_vote_on_fips = data => {
var sendback = {};
sendback.trump = _.where(adjusted_state_counties_vote, {
fips: data.fips
})[0].trump;
sendback.clinton = _.where(adjusted_state_counties_vote, {
fips: data.fips
})[0].clinton;
sendback.st_name = data.cong_dist;
return sendback;
}
Insert cell
adjusted_district_counties_vote = _.map(district_table, item => {
return join_vote_on_fips(item);
})
Insert cell
Insert cell
adjusted_vote = adjusted_state_counties_vote.concat(adjusted_district_counties_vote)
Insert cell
Insert cell
counties_grouped_by_state = _.groupBy(adjusted_vote, 'st_name')
Insert cell
Insert cell
Insert cell
test = _.reduce(
counties_grouped_by_state["Alabama"],
(memo, item) => {
return item.trump + memo;
},
0
)
Insert cell
Insert cell
Insert cell
state_and_district_totals = _.map(counties_grouped_by_state, item => {
return totaler(item);
})
Insert cell
Insert cell
d_total_electoral_votes = _.reduce(
state_and_district_totals,
(memo, item) => {
return item.d_electoral_votes + memo;
},
0
)
Insert cell
r_total_electoral_votes = _.reduce(
state_and_district_totals,
(memo, item) => {
return item.r_electoral_votes + memo;
},
0
)
Insert cell
winner = {
if (d_total_electoral_votes > r_total_electoral_votes) {
return "Democrat";
} else if (r_total_electoral_votes > d_total_electoral_votes) {
return "Republican";
} else {
return "Electoral tie";
}
}
Insert cell
Insert cell
Insert cell
// Map() can take a set of [key, value] arrays to make a reference
colordata = Object.assign(
new Map(
_.map(state_and_district_totals, item => {
return [item.st_name, item.win_color];
})
)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { slider } from "@jashkenas/inputs"
Insert cell

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.
Learn more