Skip to content

Instantly share code, notes, and snippets.

@rockchalkwushock
Created January 5, 2022 17:08
Show Gist options
  • Save rockchalkwushock/e91035be2280f7ecc95e27e87c478a89 to your computer and use it in GitHub Desktop.
Save rockchalkwushock/e91035be2280f7ecc95e27e87c478a89 to your computer and use it in GitHub Desktop.
import { eachYearOfInterval, getMonth } from 'date-fns'
import currentData from './current.json'
// array
// obj.bio.gender Filter on gender only F
// obj.terms (Array) Filter on type only rep
// get start/end
const app = () => {
const women = (currentData as Array<unknown>).filter(
// @ts-ignore
val => val.bio.gender === 'F'
)
// @ts-ignore
const terms = women
.map(({ terms }) => terms)
.flat()
.filter(term => term.type === 'rep')
// @ts-ignore
const arr = terms.map(({ end, start }) => {
const results = eachYearOfInterval({
end: new Date(end),
start: new Date(start),
})
if (getMonth(new Date(results[results.length - 1])) === 0) {
return results
.slice(0, results.length - 1)
.map(date => date.getFullYear())
}
return results.map(date => date.getFullYear())
})
// @ts-ignore
const final = arr.reduce((acc, val) => {
// @ts-ignore
val.forEach(year => {
// @ts-ignore
if (acc[year]) {
// @ts-ignore
acc[year] = acc[year] + 1
} else {
// @ts-ignore
acc[year] = 1
}
})
return acc
}, {})
console.log(final)
return 0
}
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment