79207128

Date: 2024-11-20 12:09:34
Score: 1.5
Natty:
Report link

type RecurrenceType = 'once a year' | 'twice a year' | 'quarterly' | 'monthly';

function calculateEndDate(startDate: Date, recurrence: RecurrenceType): Date { const endDate = new Date(startDate); // Copy the start date to calculate the end date

switch (recurrence) { case 'once a year': endDate.setFullYear(startDate.getFullYear() + 1); // Add 1 year break; case 'twice a year': endDate.setMonth(startDate.getMonth() + 6); // Add 6 months break; case 'quarterly': endDate.setMonth(startDate.getMonth() + 3); // Add 3 months break; case 'monthly': endDate.setMonth(startDate.getMonth() + 1); // Add 1 month break; default: throw new Error('Invalid recurrence type'); }

return endDate; }

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user28143503