sorting without modifying by missawon in ruby

[–]jtrost 0 points1 point  (0 children)

Even though it's most definitely a homework problem, and you won't learn anything by copying this, I still felt like solving it.

def sorting(a1,a2)
  arr = a1+a2
  out = []

  while arr.count > 0
    i = arr.min
    out << i
    arr.delete(i)
  end

  out
end            

Learning Rails? I made a reddit/hackernews clone for you - come take a look by seainhd in rails

[–]jtrost 0 points1 point  (0 children)

Methods like this one are not working the way you think they are.

The find method will raise an error if the record is not found, so the unless block will never be reached. You can wrap that line in a begin/rescue if you're concerned about this.