Here is a data array that I am working with:
const data = [
{ year: 1900, title: 'test 1' },
{ year: 2000, title: 'test 2' },
{ year: 2000, title: 'test 3' },
{ year: 2000, title: 'test 4' },
];
My goal is to create an array of years where each year appears more than twice:
[2000]
We can easily achieve the countBy using the following code:
_.chain(data)
.countBy('year')
.value()
This will give us the following object:
{'1900': 1, '2000': 3}
I am facing some challenges with the filtering part. When I tried the following code, it returned an empty array:
_.chain(data)
.countBy('year')
.filter((o) => {
o > 2;
})
.value();
Can someone guide me on the correct approach?