Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Declarative Sum

Modern JavaScripteasy

Course · Section 17: Modern JavaScript Development: Modules, Tooling, and Functional · Lecture 294: Declarative and Functional JavaScript Principles

Implement `declarativeSum(nums)` returning the total using `reduce` (a declarative style) rather than an imperative loop.

Sample tests

Input: declarativeSum([1,2,3])
Output: 6
Input: declarativeSum([])
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Forgetting the initial value breaks on an empty array.
Visualize this concept: ES Modules →
Approach & explanation (try first)

reduce declares the aggregation directly, a more functional style than a manual loop.

Loading...
⌘/Ctrl + Enter

Run your code to see results.