title: How to return the third largest number in an array
body: <p>My code logic to answer a programming question is:</p>
  
  <ol>
  <li>Find the biggest number in the input array.</li>
  <li>Store that number in a new array.</li>
  <li>Delete that number from the input array.</li>
  <li>Repeat #'s 1-3 until I have three elements in the new array. </li>
  <li>Choose the last element of the array to return.</li>
  </ol>
  
  <p>My code is returning three 10's, instead of the three largest elements in the array, 10, 8, and 4. I think it might be because once the inner while loop is done, the code cannot return back to it? </p>
  
  <p>My test code is:</p>
  
  <pre><code>puts(third_greatest([8, 1, 10, 4])).to_s
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>def third_greatest(nums)
    greatest_number = nil
    three_greatest = []
  
    three_greatest_idx = 0
  
    while three_greatest_idx &lt; 3
      number_idx = 0
  
      while number_idx &lt; nums.length
        current_number = nums[number_idx]
  
        if greatest_number == nil
          greatest_number = current_number
        elsif greatest_number &lt; current_number
          greatest_number = current_number
        end
  
        number_idx += 1
      end
  
      three_greatest.unshift(greatest_number)
      nums.delete(greatest_number)
      three_greatest_idx += 1
    end
  
    return three_greatest
  end
  </code></pre>