10 XP challenge
Add and Subtract Alternating Items
easy
Build it yourself · 6 min
1 Learn2 Predict3 Solve
TaskYour mission
Return numbers[0] - numbers[1] + numbers[2] - numbers[3], continuing with alternating signs. Empty input returns 0. numbers contains 0 to 30 integers from -100 to 100.
Examples
| Input | Return |
|---|---|
numbers = [1,2,3,4]total: 0 → 1 → -1 → 2 → -2. The result is -2. | -2 |
numbers = [5,-2,1]total: 0 → 5 → 7 → 8. The result is 8. | 8 |
Your code
Write your answer inside Solution, then use return to send it back.
Ln 1, Col 1
JavaScript
Try examples runs the public examples. Check my code checks your full answer and saves your completion.