Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Sum of Values

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 118: Enhanced Object Literals

Implement `sumValues(obj)` returning the sum of all numeric values.

Sample tests

Input: sumValues({"a":1,"b":2,"c":3})
Output: 6
Input: sumValues({})
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Non-numeric values would produce NaN or string concatenation; inputs here are numbers.

Learning resources

  • MDN: Object
Approach & explanation (try first)

Summing Object.values with reduce totals the numeric values.

Loading...
⌘/Ctrl + Enter

Run your code to see results.