Public
Edited
Nov 9, 2023
3 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
sortedBirthdays = sortByMostPopularBirthdates(parseInt(year))
Insert cell
mostPopularBirthday = sortedBirthdays[0].date
Insert cell
leastPopularBirthday = sortedBirthdays[sortedBirthdays.length - 1].date
Insert cell
Insert cell
function formatShortMonth(month) {
return Plot.formatMonth("en-US", "short")(month)
}
Insert cell
function getAllYears() {
return Array.from(new Set(births.map(d => d.date.getUTCFullYear()))).filter(year => year !== new Date().getUTCFullYear())
}
Insert cell
function filterByYear(year) {
return births.filter(d => d.date.getUTCFullYear() === year)
}
Insert cell
function sortByMostPopularBirthdates(year) {
const filteredData = filterByYear(year)

return filteredData.sort((a, b) => a.births > b.births ? -1 : 1)
}
Insert cell
function formatDate(date) {
return date.getUTCDate() + " " + formatShortMonth(date.getUTCMonth())
}
Insert cell
function getBirthsByDate(date) {
return births.find(d => {
return d.date.getUTCFullYear() === date.getUTCFullYear() &&
d.date.getUTCMonth() === date.getUTCMonth() &&
d.date.getUTCDate() === date.getUTCDate()
})?.births
}
Insert cell
Insert cell
births.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

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