Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Upadated reverse array code #1331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shamimsikder wants to merge 1 commit into TheAlgorithms:master
base: master
Choose a base branch
Loading
from shamimsikder:update
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions Data-Structures/Array/Reverse.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/** https://www.geeksforgeeks.org/write-a-program-to-Reverse-an-array-or-string/
* This function will accept an array and
* Reverse its elements and returns the inverted array
* @param {Array} arr array with elements of any data type
* @returns {Array} array with inverted elements
/**
* This function accepts an array and reverses its elements.
* @param {Array} arr - Array with elements of any data type.
* @returns {Array} - Array with reversed elements.
*/

const Reverse = (arr) => {
// limit specifies the amount of Reverse actions
for (let i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--) {
const temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
const reverseArray = (arr) => {
for (let i = 0, j = arr.length - 1; i < j; i++, j--) {
const temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
return arr
}
export { Reverse }
return arr;
};

export default reverseArray;

AltStyle によって変換されたページ (->オリジナル) /