Skip to content

Instantly share code, notes, and snippets.

@numb86
Created July 11, 2019 04:02
Show Gist options
  • Save numb86/d8e0aa01d751e0dcb5a116a5f4748dd9 to your computer and use it in GitHub Desktop.
Save numb86/d8e0aa01d751e0dcb5a116a5f4748dd9 to your computer and use it in GitHub Desktop.
reverse の実装
const arr = [1, 2, 3, 4, 5];
for (let i = 0; i < arr.length / 2; i++) {
const front = arr[i];
const back = arr[arr.length - 1 - i];
arr[i] = back;
arr[arr.length - 1 - i] = front;
}
console.log(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment