Created
May 23, 2018 14:00
-
-
Save sagardere/e55450641374ffaa8998edc853f318e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Swap "1-st Array elements to last" and "Last element of array to 1-st" | |
var array = [33,535,5,345,3,4,5,3,5,34,5,435]; | |
console.log("Before Swapping : " , array); | |
if(array.length != 0){ | |
var last = array.pop(); | |
var first = array[0]; | |
var len = array.length - 1; | |
array[0] = last; | |
array[len] = first; | |
console.log("After Swapping : ", array); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment