Skip to content

Instantly share code, notes, and snippets.

@Deityhub
Last active August 27, 2022 15:42
Show Gist options
  • Save Deityhub/68a507b96a9b1f1be669ca3a8d40c957 to your computer and use it in GitHub Desktop.
Save Deityhub/68a507b96a9b1f1be669ca3a8d40c957 to your computer and use it in GitHub Desktop.
Reverse an array in place by swapping
function reverseArr(arr) {
const n = parseInt(arr.length/2);
for(let i = 0; i < n; i++) {
const temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment