Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Count Completed

Derived Stateeasy

Course · Section 11: Working With Arrays · Lecture 160: The reduce Method

Implement `countCompleted(todos)` returning how many todos have `done: true`.

Sample tests

Input: countCompleted([{"done":true},{"done":false},{"done":true}])
Output: 2
Input: countCompleted([])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Keeping a separate completed counter in state that can fall out of sync.

Learning resources

  • React: Choosing the State Structure
Approach & explanation (try first)

Count completed todos directly from the list each render, so the number can never disagree with the data.

Loading...
⌘/Ctrl + Enter

Run your code to see results.