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.

  1. Retrieve the element at index 0.
  2. Retrieve the last element using length - 1.
  3. Sum them and print the result.
  4. If empty, print 0. If single element, sum it with itself.

01EXAMPLE 1

Input[10, 20, 30]
Output40

Explanation: 10 + 30 = 40.

Constraints

  • Correct index calculation for last item.
Arrays
JavaScript
Loading...
1 Hidden

Input Arguments

values[10,20,30]

Expected Output

40

Click RUN to test your solution