Challenge
Let's have a list L
of n
elements. The task is to swap every two elements in this list.
Constrains
- the list
L
has at least two elements - size of the list
L
is a multiple of two (i.e. number of elements is even)
Example
input:
[1,2,3,4,5,6]
output:
[2,1,4,3,6,5]
input:
[0,1,0,1]
output:
[1,0,1,0]
Rules
- this is
code-golf
challenge, so the shortest code wins - standard rules apply for your answer with default I/O rules, so you are allowed to use stdin/stdout, functions/method with the proper parameters and return-type, full programs
- default Loopholes are forbidden.
char[]
array in a language like C? If so, there is a certain built-in that would make the answer very short (s***
). \$\endgroup\$