Created
July 2, 2021 17:37
-
-
Save jasp402/bfa1c410885a742d860ab0ba081e2d40 to your computer and use it in GitHub Desktop.
reordenamiento de un array segun los dias de la semana y las horas dada.
This file contains hidden or 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 days = ["Lun","Mar","Mie","Juv","Vie","Sab","Dom"] | |
const userSchedule = [ | |
[], | |
['17:00', '18:00', '19:00'], | |
['17:00', '18:00', '19:00'], | |
['17:00'], | |
['17:00', '18:00', '19:00'], | |
['17:00', '18:00', '19:00'], | |
[] | |
]; | |
const result = userSchedule.reduce((acc={}, item, i) => { | |
item.forEach(x =>acc[x] = acc[x] ? acc[x].concat(days[i-1]) : [days[0]]); | |
return acc | |
},{}); | |
console.log(result); | |
/* | |
{ | |
'17:00': [ 'Lun', 'Mar', 'Mie', 'Juv', 'Vie' ], | |
'18:00': [ 'Lun', 'Mar', 'Juv', 'Vie' ], | |
'19:00': [ 'Lun', 'Mar', 'Juv', 'Vie' ] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment