-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
calculating and updating the streak each day
- Loading branch information
Showing
3 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Get unique dates on which tasks have been completed | ||
* @param {Array} goals - List of goal objects, each containing microgoals and tasks | ||
* @returns {Array} - Unique dates when tasks were marked as completed | ||
*/ | ||
export const getCompletedDates = (goals) => { | ||
const completedDates = new Set(); | ||
|
||
// Check if goals is an array and iterate only if it exists | ||
if (Array.isArray(goals)) { | ||
goals.forEach((goal) => { | ||
// Ensure microgoals is defined and an array | ||
if (Array.isArray(goal.microgoals)) { | ||
goal.microgoals.forEach((microGoal) => { | ||
// Ensure tasks is defined and an array | ||
if (Array.isArray(microGoal.tasks)) { | ||
microGoal.tasks.forEach((task) => { | ||
// Check for both task completion and valid completion date | ||
if (task.completed && task.completionDate) { | ||
completedDates.add(task.completionDate); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
return Array.from(completedDates); | ||
}; |