First & Last
EasyAcc. 98.9%
+15 XP 5
Boundary Sum
A quick test of array index access.
The Assignment
Your function receives an array values.
- Retrieve the element at index 0.
- Retrieve the last element using length - 1.
- Sum them and print the result.
- If empty, print 0. If single element, sum it with itself.
01EXAMPLE 1
Input
[10, 20, 30]Output
40Explanation: 10 + 30 = 40.
Constraints
- Correct index calculation for last item.
Arrays
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
values[10,20,30]
Expected Output
40
Click RUN to test your solution