Interview question of the issue #260 of rendezvous with cassidoo.
Given a list, swap every two adjacent nodes. Something to think about: How would your code change if this were a linked list, versus an array?
Example:
> swapPairs([1,2,3,4])
> [2,1,4,3]
> swapPairs([])
> []
Just pnpm i
to install all dependencies and then pnpm t
to run the tests!