**DISCLAIMER**

> 
> I am well aware of the duplicate questions, however this one is asking to remove duplicates without making a new array and wants us to mutate the original array.
> 
> 
> 

**INSTRUCTIONS**

> 
> Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
> 
> 
> Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
> 
> 
> 

**EXAMPLE**

Given `nums = [1,1,2]`,

Your function should return length = 2, with the first two elements of `nums` being 1 and 2 respectively.

It doesn't matter what you leave beyond the returned length.

**ATTEMPT**

```js
const removeDuplicates = function(nums) {

   for(let i of nums){
     if(nums[i] === nums[i]){
        nums.splice(i, 1)
     }
   }
   return nums.length;
};

console.log(removeDuplicates([1, 1, 2]));
console.log(removeDuplicates([1, 2]));

// [1, 1, 2] => [1, 2] (Correct)
// [1, 2]    => [1]    (Incorrect - should be [1, 2])
```

Am I mutating the array correctly with splice and what do I need to do to correct the 2nd argument?

Also, in leetcode, when I run the first argument, it says it's correct and returns the array of the leftover elements, but the instructions were asking for the length of the new array. Not sure if I'm missing something but why is it not returning the length?

<https://imgur.com/5cuhFYf>