Created
September 1, 2022 17:53
-
-
Save akobashikawa/2c128abc40d58afea1cd99eb65849119 to your computer and use it in GitHub Desktop.
Devolver un json con fechas agrupadas por día, a partir de una lista de fechas
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
const fechas = ["01/12/2021", "06/12/2021", "08/12/2021", "13/12/2021", "15/12/2021", "20/12/2021", "22/12/2021", "27/12/2021", "29/12/2021", "04/09/2022"]; | |
const fechasAgrupadas = { | |
lunes: [], | |
martes: [], | |
miercoles: [], | |
jueves: [], | |
viernes: [], | |
sabado: [], | |
domingo: [], | |
}; | |
for (let fecha of fechas) { | |
const dias = ["domingo", "lunes", "martes", "miercoles", "jueves", "viernes", "sabado"]; | |
const fechaParts = fecha.split('/'); | |
const dia = new Date(fechaParts[1]+'/'+fechaParts[0]+'/'+fechaParts[2]); | |
const dow = dia.getDay(); | |
console.log(fecha, dia, dow, dias[dow]); | |
fechasAgrupadas[dias[dow]].push(fecha); | |
} | |
console.log(fechasAgrupadas); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment