Javascript: obtener el lunes y domingo de la semana anterior
Estoy usando el siguiente script para obtener el lunes (primero) y el domingo (último) para la semana anterior:
var curr = new Date; // get current date
var first = curr.getDate() - curr.getDay() - 6; // Gets day of the month (e.g. 21) - the day of the week (e.g. wednesday = 3) = Sunday (18th) - 6
var last = first + 6; // last day is the first day + 6
var startDate = new Date(curr.setDate(first));
var endDate = new Date(curr.setDate(last));
Esto funciona bien si el último lunes y el domingo también fueron en el mismo mes, pero me di cuenta hoy que no funciona si hoy es diciembre y el último lunes fue en noviembre.
Soy un novato total de JS, ¿hay otra forma de obtener estas fechas?