Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
Array methods exercise

I need help for this exercise:

Array methods

Implement the uncompletedNotes function which, given an array of notes, returns only the uncompleted notes. A note is considered completed if all todo present have the done flag set to true.

This is what I've done:

function uncompletedNotes(notes) {

  let result = []

  notes.forEach(element => {
    if (element.todos.done == false) {
      result.push(element);
    }
  });

  return result;

}

const notes = [{
    id: 1,
    description: 'Workout program',
    todos: [{
        id: 1,
        name: 'Push ups - 10 x 3',
        done: false
      },
      {
        id: 2,
        name: 'Abdominals - 20 x 3',
        done: true
      },
      {
        id: 3,
        name: 'Tapis Roulant - 15min',
        done: true
      }
    ]
  },
  {
    id: 2,
    description: 'Front-end Roadmap',
    todos: [{
        id: 1,
        name: 'Learn HTML',
        done: true
      },
      {
        id: 2,
        name: 'Learn CSS',
        done: true
      },
      {
        id: 3,
        name: 'Learn JavaScript',
        done: true
      },
      {
        id: 4,
        name: 'Learn Angular',
        done: true
      }
    ]
  }
]

const notesInProgress = uncompletedNotes(notes);
console.log('All notes: ', notes);
console.log('Notes In Progress: ', notesInProgress);

But it gives me an empty array result in Notes in Progress.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

function uncompletedNotes(notes) {
    return notes.filter(note => note.todos.filter(todo => !todo.done))
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

The problem here is that the todos property of each notes is itself an array, ie there is no done property on todos. It may be useful to look at the array methods every or some (likely some), which will return true if any item in an iterable returns true for a given condition.

 function uncompletedNotes(notes) {
  
  let result = []
      
      notes.forEach(element => {
        if(element.todos.some(todo => todo.done === false)) {
          result.push(element);
        }
      });

   return result;

  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Todos is also an array, so you'd have to iterate over that one as well

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda