title: Return the first duplicate number from an array
body: <p>I'm trying to solve a simple challenge where I write a function that returns the <em>first</em> duplicate number in an array.</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>function duplicateNumber(arr) {
      for (var i = 0; i &lt; arr.length; i++) {
          for (var j = arr.length; j &gt;= 0; j--) {
              if (arr[i] === arr[j]) {
                  var dup_num = arr[i]
              }
          }
      }
      return dup_num
  }
  </code></pre>
  
  <p>It doesn't seem to be working. What am I doing wrong?</p>
  
  <p>Just realized I'm also looping from end to beginning <em>and</em> beginning to end.</p>
  
  <p>in the array = <code>[3, 5, 6, 8, 5, 3]</code></p>
  
  <p>the duplicate number should be <code>5</code> since it's duplicated before 3.</p>