From cf55a828df9fc8f9e32ec1d3a9fa6a5eab163c28 Mon Sep 17 00:00:00 2001 From: Ayeza Bashir Date: Sun, 8 Oct 2023 17:38:51 +0500 Subject: [PATCH 1/4] Update Solution.js --- Easy/26. Remove Duplicates from Sorted Array/Solution.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Easy/26. Remove Duplicates from Sorted Array/Solution.js b/Easy/26. Remove Duplicates from Sorted Array/Solution.js index 833ed83..1be20a6 100644 --- a/Easy/26. Remove Duplicates from Sorted Array/Solution.js +++ b/Easy/26. Remove Duplicates from Sorted Array/Solution.js @@ -1,3 +1,4 @@ +// Solution # 1 const removeDuplicates = function (nums) { let uniqueCount = 1; // Initialize the count of unique elements. @@ -11,3 +12,9 @@ const removeDuplicates = function (nums) { return uniqueCount; }; + +// Solution # 2 +const removeDuplicates = function (nums) { + return [...new Set(nums)]; + // A Set is a built-in JavaScript data structure that only stores unique values, so any duplicates in the nums array are automatically removed when creating the Set. +} From 5a1969a97c0cd8fed907cf665bd35553ba810f61 Mon Sep 17 00:00:00 2001 From: Ayeza Bashir Date: Sun, 8 Oct 2023 17:43:03 +0500 Subject: [PATCH 2/4] Create Solution.js --- Easy/344. Reverse String/Solution.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Easy/344. Reverse String/Solution.js diff --git a/Easy/344. Reverse String/Solution.js b/Easy/344. Reverse String/Solution.js new file mode 100644 index 0000000..6ae7d25 --- /dev/null +++ b/Easy/344. Reverse String/Solution.js @@ -0,0 +1,4 @@ +var reverseString = function (s) { + s.reverse(); + return s; +}; From 00bc768c30c96bd2cd85fe41b258267562704389 Mon Sep 17 00:00:00 2001 From: Ayeza Bashir Date: Mon, 9 Oct 2023 22:48:23 +0500 Subject: [PATCH 3/4] Update Solution.js --- Easy/26. Remove Duplicates from Sorted Array/Solution.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Easy/26. Remove Duplicates from Sorted Array/Solution.js b/Easy/26. Remove Duplicates from Sorted Array/Solution.js index 1be20a6..f2ebba1 100644 --- a/Easy/26. Remove Duplicates from Sorted Array/Solution.js +++ b/Easy/26. Remove Duplicates from Sorted Array/Solution.js @@ -15,6 +15,7 @@ const removeDuplicates = function (nums) { // Solution # 2 const removeDuplicates = function (nums) { - return [...new Set(nums)]; + let k = [...new Set(nums)]; + return k.length; // A Set is a built-in JavaScript data structure that only stores unique values, so any duplicates in the nums array are automatically removed when creating the Set. } From f9a0d3bdbb072c85a94db4a155d34533c863e9cd Mon Sep 17 00:00:00 2001 From: Ayeza Bashir Date: Wed, 11 Oct 2023 12:12:31 +0500 Subject: [PATCH 4/4] Update Solution.js --- .../Solution.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Easy/26. Remove Duplicates from Sorted Array/Solution.js b/Easy/26. Remove Duplicates from Sorted Array/Solution.js index f2ebba1..57d3583 100644 --- a/Easy/26. Remove Duplicates from Sorted Array/Solution.js +++ b/Easy/26. Remove Duplicates from Sorted Array/Solution.js @@ -14,8 +14,13 @@ const removeDuplicates = function (nums) { }; // Solution # 2 -const removeDuplicates = function (nums) { - let k = [...new Set(nums)]; - return k.length; - // A Set is a built-in JavaScript data structure that only stores unique values, so any duplicates in the nums array are automatically removed when creating the Set. +function removeDuplicates(nums) { + // Use filter to create a new array with unique elements + const uniqueArray = nums.filter((value, index) => nums.indexOf(value) === index); + + // Copy the unique elements back to the original array + for (let i = 0; i < uniqueArray.length; i++) { + nums[i] = uniqueArray[i]; + } + return uniqueArray.length; }