r/JavaScriptHelp • u/killMeSak • Mar 14 '22
❔ Unanswered ❔ Get count and format
I have an object dateRange ={ 2021-08-06 - 2021-09-06 : 0, 2021-09-06 -2021-10-06 : 0}
I also have another array dateArr=[2021-08-06, 2021-11-06]. Desired res = [{key: 2021-08-06 - 2021-09-06 , value: 1}, { key: 2021-09-06 -2021-10-06 , value: 0}] where value contains the number of occurrences of values inside dateArr as per dateRange.
How can I achieve this?
2
Upvotes
1
u/trplclick Mar 14 '22
This should achieve what you want. I've commented it so it should be easy to follow, but any questions let me know!
I've also created a JS bin so you can see it working and play around with it if you like. https://jsbin.com/lezatupeqi/edit?js,console