Playground - Crea un organizador de tareas
Clase 85 de 99 • 30 días de JavaScript
Contenido del curso
Clase 85 de 99 • 30 días de JavaScript
Contenido del curso
David Ochoa
Pablo Pincay Alvarez
Angel Javier Sanchez Tenjo
Frandel Corporan Rodríguez
Andres Eduardo Maneiro Antunez
Alejandro Naranjo
Leonardo de los angeles Espinoza Hernandez
Joan Alexander Valerio Rodríguez
Jacobo Burbano
Rubén Hernández Hernández
Gonzalo Gutiérrez Castillo
Elias Rayas Gonzalez
Victor Hernandez
Esteban Alzate Atehortua
Pablo Pincay Alvarez
Alexis Corrales
Hiver Tapia
Alejandro Anaya
Abril Darynka Tapia Sosa
Jose Carlos Machado
Carina Payleman
Victor Ortiz
Escudo anti-spoilers
!Nyan Cat Programming
Algo que no queda muy claro es que se debe generar un Set por cada tarea donde se contenga los tags.
Por lo demás un excelente reto.
Nunca pares de aprender
export function taskManager() { // Creo un nuevo Map let tasks = new Map(); function addTask(task, tags) { // Se convierte el nombre de la tarea a lowercase para ser comparadad task = task.toLowerCase(); // En caso de existir la tarea, agrega nuevos tags a su Set de tags if (tasks.has(task)) { const existingTags = tasks.get(task); console.log(existingTags); tags.forEach((tag) => existingTags.add(tag)); } // De no existir la tarea crea un nuevo set que contenga sus tags y adicionalmente // agrega la tarea ale Map de tareas else { const newTags = new Set(tags); tasks.set(task, newTags); } } function printTasks() { // Retorno las tareas return tasks } return { addTask, printTasks }; }
Bonito escudo anti spoilers xd
Hola, comparto la solución; me toco auto spoliarme... pero entendi que debia hacer.
✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
export function taskManager() { const tasks = new Map(); const addTask = function (task, tags) { task = task.toLowerCase(); if (tasks.has(task)) { const existingTags = tasks.get(task); tags.forEach((tag) => existingTags.add(tag)); } else { const newTags = new Set(tags); tasks.set(task, newTags); } }; const printTasks = function () { return tasks; }; return { addTask, printTasks }; }
Me gusto este playground 💚
export function taskManager() { const tasks = new Map() function addTask(task, tags) { task = task.toLowerCase() if (tasks.has(task)) { const currentTags = tasks.get(task) const updateTags = [...currentTags,...tags] tasks.set(task, new Set(updateTags)) } else { tasks.set(task, new Set(tags)) } } function printTasks() { return tasks } return{addTask,printTasks} }
Mi solucion . . . . . . . . . . . . . . . . . . .
ecport function taskManager() { let tasks = new Map() return { addTask(task, tags) { const newTask = task.toLowerCase() if (!tasks.has(newTask)) { tasks.set(newTask, new Set(tags)) } else { tags.forEach(tag => tasks.get(newTask).add(tag)) } }, printTasks() { return tasks } } }
Cuando ejecuto este código, el playground me genera errores en “Vista” y no me habilita el botón para correr pruebas. Sin embargo dentro de mi equipo el código hace lo que creo que se está solicitando.
<code> export function taskManager() { const taskMap = new Map(); function addTask(task, tags) { const taskLowerCase = task.toLowerCase(); if (taskMap.has(taskLowerCase)) { const tagging = taskMap.get(taskLowerCase); tags.forEach(tag => tagging.add(tag)); } else { const tagging = new Set(tags); taskMap.set(taskLowerCase, tagging); } } function printTasks() { const result = new Map(); for (const [task, tagging] of taskMap.entries()) { const tags = Array.from(tagging); result.set(task, tags); } return result; } this.addTask = addTask; this.printTasks = printTasks; }
¡Hola @alejonaranjo83!
Para que el ejercicio pueda correr y ejecutar las pruebas debes de regresar un closure, solamente el retornar las 2 funciones creadas y con ello deberás tener un resultado diferente
Me avisas si esto te es de ayuda, cualquier cosa siempre me la puedes hacer saber :D
Crei que seria facil y dure casi tres horas xD, pero bueno aqui dejo mi ejercicio . . . . . . . . . . . . . . . .
function abstractLowerCase(string) { return string.toLowerCase() } export function taskManager() { let objetoMap = new Map() return { addTask: (task, tags) => { if (!objetoMap.has(abstractLowerCase(task))) { objetoMap.set(abstractLowerCase(task), new Set(tags)) } else { for (let i = 0; i < tags.length; i++) { objetoMap.get(abstractLowerCase(task)).add(tags[i]) } } }, printTasks: () => { return objetoMap } } }
💚Mi Solución 💚
🛡️ESCUDO ANTI-SPOILERS🛡️
!cats
👾Código
export function taskManager() { const tasksMap = new Map() const addTask = (task, tags) => { const taskLowerCase = task.toLowerCase() if (tasksMap.has(taskLowerCase)) { const taskTags = tasksMap.get(taskLowerCase) tags.forEach(tag => taskTags.add(tag)) } else { tasksMap.set(taskLowerCase,new Set(tags)) } } const printTasks = () => { return tasksMap } return { addTask, printTasks } }
Mi solucion: . . . . . . .
function taskManager() { const tasks = new Map() const addTask = (task, tags) => { const newTask = task.toLowerCase() const hasTask = tasks.has(task) if (!hasTask) { tasks.set(newTask, new Set(tags)) } else { let current = tasks.get(newTask) tasks.set(newTask, new Set([...current,...tags])) } } const printTasks = () => { return tasks } return { addTask, printTasks } }
Solución
function taskManager() { // Tu código aquí 👈 const tasks = new Map() function addTask(task, tag) { task = task.toLowerCase() // Check for existing tasks in map if (tasks.has(task)) { tag.forEach(item => tasks.get(task).add(item)) return } // If it does not exists we create a new task tasks.set( task, new Set([...tag]) ) } function printTask() { return tasks } return { addTask, printTask } }
export function taskManager() { const map = new Map(); const addTask = (task, tags) => { task = task.toLowerCase(); if (!map.get(task)) { map.set(task, new Set(tags)); } else { const tag = map.get(task); for (let t of tags) { tag.add(t); } map.set(task, tag); } }; const printTasks = () => { return map; }; return { addTask, printTasks }; }
Mi solución! . . . . . . . . . . . . . . . . . . . . .
export function taskManager() { let map = new Map(); return { "addTask": (task, tags) => { task = task.toLowerCase(); if (!map.has(task)) { map.set(task, new Set(tags)); } else { const tagSet = map.get(task); for (const tag of tags) { tagSet.add(tag); } map.set(task, tagSet); } }, "printTasks":() =>{ return map; } } }
.. . . SPOILERS <3 . . . . . . . . . . . .
export function taskManager() { const tasks = new Map() return { addTask: (task, tags) => { task = task.toLowerCase() if (tasks.has(task)) { const newTags = [...tasks.get(task), ...tags] tasks.set(task, new Set(newTags)) } else { tasks.set(task, new Set(tags)) } }, printTasks: () => tasks } }
export function taskManager() { const tasks = new Map(); const addTask = function (task, tags) { const result = task.toLowerCase(); const existingTask = tasks.get(result); if (existingTask) { tags.forEach(tag => existingTask.add(tag)); } else { tasks.set(result, new Set(tags)); } }; const printTasks = function () { return tasks; }; return { addTask, printTasks }; }
aquí mi versión
export function taskManager() { const tasks = new Map() return { addTask(task, tags) { task = task.toLowerCase() if (!tasks.has(task)) tasks.set(task, new Set(tags)) else tags.forEach(tag => tasks.get(task).add(tag)) }, printTasks() { return tasks } } }
🛡️🛡️Escudo anti-spoilers🛡️🛡️
Personalmente me gusta más como se organiza el código con el azúcar sintáctico de JS usando 'class' en vez de usar closures, al final el código puede hacer lo mismo, son solo gustos...
class Tasks{ constructor() { this.tasks = new Map() } addTask(task, tags) { task = task.toLowerCase() if (this.tasks.has(task)) { this.tasks.set(task, new Set([...this.tasks.get(task), ...tags])) } else { this.tasks.set(task, new Set(tags)) } } printTasks() { return this.tasks } } export const taskManager = () => new Tasks()
Hola, dejo mi solución: . . . . . . . . . .
export function taskManager() { // Tu código aquí 👈 let tasks = new Map(); const addTask = (task, tags) => { const taskLowerCase = task.toLowerCase(); const existTask = tasks.has(taskLowerCase); if(existTask){ tasks.get(taskLowerCase) tags.forEach(item => tasks.get(taskLowerCase).add(item)); }else{ tasks.set(taskLowerCase, new Set(tags)); } }; const printTasks = () => tasks; return { addTask, printTasks } }
En las pruebas se llama directamente las funciones y no desde la variable que contiene el closure. Aquí dejo mi aporte... :)
export function taskManager() { // Tu código aquí 👈 let org = new Map(); function addTask(task, tags) { let lowertask = task.toLowerCase() if (org.has(lowertask)) { for (let tag of tags) { org.get(lowertask).add(tag) } } else { org.set(lowertask, new Set(tags)) } } function printTasks() { return org } return { addTask, printTasks } }
export function taskManager() { let tasks = new Map(); function addTask(task, tags) { let duplicatedTask = task.toLowerCase(); if (!tasks.has(duplicatedTask)) { tasks.set(duplicatedTask, new Set(tags)); } else { tags.forEach(tag => tasks.get(duplicatedTask).add(tag)); } } function printTasks() { return tasks; } return { addTask, printTasks } }
Mi solución, me quedo buena: . . . . . . . . . . . . . . . . . . . . .
export function taskManager() { // Tu código aquí 👈 let map = new Map(); return { addTask(task, tags) { if (map.has(task.toLowerCase())) { tags.forEach(tag => map.get(task.toLowerCase()).add(tag)); } else { map.set(task.toLowerCase(), new Set(tags)); } }, printTasks() { console.log(map) return map; } } }