title: Coderbyte Second Great Low - code works but is rejected
body: <p>I'm currently working through the Coderbyte series to get better at Ruby programming.  Maybe this is just a bug in their site (I don't know), but my code works for me everywhere else besides on Coderbyte.</p>
  
  <p>The purpose of the method is to return the 2nd smallest and the 2nd largest elements in any inputted array.</p>
  
  <p>Code:</p>
  
  <pre><code>def SecondGreatLow(arr)
    arr=arr.sort!
    output=[]
    j=1
    i=(arr.length-1)
    secSmall=''
    secLarge=''
    while output.length &lt; 1
      unless arr.length &lt;= 2
        #Get second largest here
        while (j&lt;arr.length)
          unless arr[j]==arr[j-1]
            unless secSmall != ''
              secSmall=arr[j]
              output.push(secSmall)
            end
          end
         j+=1
        end
        #get second smallest here
        while i&gt;0
          unless arr[i-1] == arr[i]
            unless secLarge != ''
              secLarge=arr[i-1]
              output.push(secLarge)
            end
          end
          i-=1
        end
  
  
       end
    end
  
  
  
    # code goes here
    return output 
  
  end   
  
  
  # keep this function call here 
  # to see how to enter arguments in Ruby scroll down   
  SecondGreatLow(STDIN.gets)
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <ol>
  <li>Input: [1,2,3,100] => Output: [2,3] (correct)</li>
  <li>Input: [1,42,42,180] => Output: [42,42] (correct)</li>
  <li>Input: [4,90] => Output: [90,4] (correct)</li>
  </ol>
  
  <p>The problem is that I'm awarded 0 points and it tells me that my output was incorrect for every test. Yet, when I actually put any inputs in, it gives me the output that I expect. Can someone please assist with what the problem might be? Thanks!</p>
  
  <p><strong>Update</strong>
  Thanks to @pjs answer below, I realized this could be done in just a few lines:</p>
  
  <pre><code>def SecondGreatLow(arr)
    arr=arr.sort!.uniq
    return "#{arr[1]} #{arr[-2]}"     
  end
  
  # keep this function call here 
  # to see how to enter arguments in Ruby scroll down   
  SecondGreatLow(STDIN.gets) 
  </code></pre>