Get longest consecutive date 'streak' [Answered]
I'm trying to figure out a nice way of getting a date-streak from a list of objects which will have activities on them. The premise to the problem is, each user records their 'excercise' which can be multiples per day. I don't care about anything other than some acceptence criteria (namely, duration of the exercise) but I can group these effectively into some structure I assume of:
This would indicate if the user has completed an activity on that date.
Where I'm struggling is to then calculate the streak of dates (the largest streak) in that full list, ie:
Here the users top 'streak' is going to be 2, as completed on the 3rd and 4th
14 Replies
this sounds very similar to the classic 'gaps and islands' problem often seen in SQL
I may be structuring the data wrong initially and is not gospel
a manual way to do it would be to loop through the entire collection with a 'currentStreak' and 'largestStreak' counters
increment current streak if current item is true, increment largestStreak if it's larger
yeah, like that
I won't have access to SQL unfortunately, so that looks like a good idea
this would be definitely more complicated in SQL
yeah, i'm not suggesting to use SQL, just giving you a name you can google to look around for other ideas if necessary
yeah appreciate that, never heard it before so some nice reading
Thanks folks!
you can use '/close' to end the thread now
let me steal the code first then I will
✅ This post has been marked as answered!
Oh it doesn't delete?
awesome
✅ This post has been marked as answered!