10 XP challenge
Swap Every Neighboring Pair
easy
Build it yourself · 6 min
1 Learn2 Predict3 Solve
TaskYour mission
Swap each neighboring pair in numbers: positions 0 and 1, then 2 and 3, and so on. Leave an unmatched final item unchanged. numbers contains 0 to 30 integers from -100 to 100.
Examples
| Input | Return |
|---|---|
numbers = [1,2,3]answer: [] → [2] → [2,1] → [2,1,3]. The result is [2,1,3]. | [2,1,3] |
numbers = [1,2,3,4]answer: [] → [2] → [2,1] → [2,1,4] → [2,1,4,3]. The result is [2,1,4,3]. | [2,1,4,3] |
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.