Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Todo List

Object-Oriented Programmingeasy

Course · Section 14: Object-Oriented Programming (OOP) With JavaScript · Lecture 226: ES6 Classes

Model a todo list. Implement `TodoList`: - `add(text)` adds an undone todo. - `toggle(index)` flips the done state of a todo. - `remaining()` returns how many todos are not done.

Examples

Input: add('a'), add('b'), add('c'), toggle(1), remaining(), toggle(0), remaining()
Output: [2, 1]
After toggling one done, two remain; after a second, one remains.

Sample tests

Input: add three, toggle two
Output: [2,1]
Input: toggle twice returns to undone
Output: 1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Toggling an out-of-range index should be a safe no-op.
Approach & explanation (try first)

Each todo carries a done flag; toggling flips it and remaining filters the undone ones.

Loading...
⌘/Ctrl + Enter

Run your code to see results.