title: understanding code for removing duplicates
body: <p>Sorry if this is a dumb question, but I'm having trouble wrapping my head around why this code works to remove dupilcates.</p>
  
  <pre><code>var removeDuplicates = function(nums) {
      if (!nums.length) return 0
      let j = 0;
      for (let i=0; i&lt; nums.length; i++) {
         if ( nums[i] !== nums[j] ) {
             j++;
             nums[j] = nums[i]
         }
      }
      return j + 1
  };
  </code></pre>
  
  <p>I am playing around on leetcode and this was my answer. </p>
  
  <pre><code>var removeDuplicates = function(nums) {
      let isDuplicates = true
      let counter = 0
      while (isDuplicates) {
          isDuplicates = false
          for (let i=0; i&lt;= nums.length - counter; i++){
              helper(nums, i, i+1)
              isDuplicates = true
          }
          counter++ 
      }
      return nums.length
  };
  function helper(array, i, j){
  if (array[i] === array[j]) array.splice(i, 1);
  
  }
  </code></pre>
  
  <p>I came across the first code looking through other solutions, I am trying to improve and grasp the details. I realize my helper probably is not optimal, but I am playing around and learning. Thanks for everyones time!</p>