Skip Iteration
MediumAcc. 91.2%
+25 XP 10
Selective Scanning
Your task is to sum every second element (index 0, 2, 4...) in the array.
The Assignment
Your function receives an array data.
- Use a loop where the index incrementer is
i += 2. - Sum the elements at these indices.
- Print the final sum.
01EXAMPLE 1
Input
[1, 10, 2, 20]Output
3Explanation: 1 + 2 = 3.
Constraints
- Stop before the end of the array.
ArraysLoops
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
data[1,10,2,20]
Expected Output
3
Click RUN to test your solution