Skip to content
Open
Show file tree
Hide file tree
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
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
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change.

* 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;
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ JavaScript Repository of TheAlgorithms, which implements various algorithms and

<h4 align="center">
These implementations are for demonstrative purposes only. Dedicated implementations of these algorithms and data
structures are much better for performance and security reasons. We also do not provide any guarantee for api stability.
structures are much better for performance and security reasons. We also do not provide any guarantee for API stability.
</h4>

---
Expand Down