Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Percent Complete

Derived Statemedium

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

Implement `percentComplete(todos)` returning the rounded percentage of todos that are done, or `0` for an empty list.

Sample tests

Input: percentComplete([{"done":true},{"done":false}])
Output: 50
Input: percentComplete([])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Dividing by zero for an empty list yields NaN.
  • Forgetting to round, leaving long decimals.

Learning resources

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

Guard the empty case to return 0, then round the done-over-total ratio times 100 for a clean percentage.

Loading...
⌘/Ctrl + Enter

Run your code to see results.