Skip to content
Advertisement

swap each element with its neighbour element in an array

I need to write a program. This method will take integer array as input and return array where each value is swapped with its neighbour element. In case the array has odd count, then last element is not swapped.

JavaScript

Result:

JavaScript

I tried using nested for loops but didnt get it

JavaScript

Advertisement

Answer

Where is the code you tried so far ?!

Anyway

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement