From 02798e8899d96d46a1a4aef74a2d213d7bd24d60 Mon Sep 17 00:00:00 2001 From: shamimsikder Date: Tue, 27 Jun 2023 14:04:55 +0600 Subject: [PATCH 1/2] Upadated reverse array code --- Data-Structures/Array/Reverse.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Data-Structures/Array/Reverse.js b/Data-Structures/Array/Reverse.js index 79a789c017..6cd7aa9473 100644 --- a/Data-Structures/Array/Reverse.js +++ b/Data-Structures/Array/Reverse.js @@ -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; From ff4671d93468a96b5d0019cb3ac61a2c8b56fe26 Mon Sep 17 00:00:00 2001 From: shamimsikder Date: Tue, 27 Jun 2023 14:13:02 +0600 Subject: [PATCH 2/2] Upadated Reademe.md files grammer mistake --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 758bb5a040..10e78a3201 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ JavaScript Repository of TheAlgorithms, which implements various algorithms and

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.

---