Overview
Combine a loop, objects and a condition to write the status line under a todo list, the kind every task app shows.
- Looping over an array of objects
- Checking for an empty array with length === 0
Short Course
Each todo is an object, so loop over the array and read todo.done. The
trap: list == [] is always false, because arrays are compared by
identity. Check list.length === 0 instead.
const todos = [{ title: "Email", done: true }];
todos == []; // false, even for an empty list
todos.length === 0; // false
for (const todo of todos) {
console.log(todo.title, todo.done); // Email true
}
Task
Write summary(todos) that returns "<done> of <total> done", or
"Nothing to do" for an empty list, e.g. three todos with two done return
2 of 3 done.
Test Suites
Pending
Next
Output