Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
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 answers
Answer question

0

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

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 Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!