Created
July 25, 2023 03:35
-
-
Save suhailgupta03/05603ff42388033ceaff21a78ca520bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let arr = [1, 2, 3, 4, 5]; | |
let start = 0; | |
let end = arr.length - 1; | |
while (start < end) { | |
let temp = arr[start]; | |
arr[start] = arr[end]; | |
arr[end] = temp; | |
start++; | |
end--; | |
} | |
console.log(arr); // Output: [5, 4, 3, 2, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment