Debug by tracing state

The sample should sum every number. What is the first incorrect state, and how would you fix it?

Examples

Example 1

Input
[8, 4, 2]
Expected output
14

Example 2

Input
[8]
Expected output
8

Hints and solution

Hint 1

What index should be visited first?

Reveal worked answer

The first loop iteration starts at index 1 instead of index 0. Start at zero, or iterate directly over values when the position is irrelevant. The corrected total is 14.

Back to the lesson