Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Count Errors

Events & Formseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 111: The Spread Operator (...)

Implement `countErrors(errors)` returning the number of fields in the errors object.

Sample tests

Input: countErrors({"a":"x","b":"y"})
Output: 2
Input: countErrors({})
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Counting nested values instead of top-level fields.

Learning resources

  • React: Reacting to Input with State
Approach & explanation (try first)

The number of error fields is just the count of keys, handy for disabling a submit button while errors remain.

Loading...
⌘/Ctrl + Enter

Run your code to see results.