How can I get how many Sundays there are between now and the end of the month? I’m not really experienced with JS date objects, so I don’t know where to start. I could loop through the days between now and the end of the month and check if the day is Sunday, but that would be only a worst-case solution.
Anyone got any idea about this?
If it’s only from now and end of the month, the worst case if only O(31) which is VERY MUCH you can say it’s as fast as O(1). The small optimization could be done by finding the first sunday then add 7 a couple of times until it passes or equals to 28, count that “couple of times” + 1 (for the first sunday) and you get the number of sundays. The worst case is now around O(10), O(7) for finding the first sunday, O(3) for the loop. But really, do you want to do this?
NOTE: maybe I miscount the complexity a little, but it’s around those numbers.