Advertisement
Guest User

smaller of 2 first indexes

a guest
Nov 13th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.28 KB | None | 0 0
  1. #Return the smaller of x[0] and y[0]
  2. #only return nil if both y[0] and y[0] are nil
  3. #x and y may possibly be empty arrays
  4. def min_first_element x, y
  5.   if x[0] and y[0] #both are non-empty
  6.     [x[0],y[0]].min
  7.   elsif x[0]
  8.     x[0]
  9.   elsif y[0]
  10.     y[0]
  11.   else
  12.     nil
  13.   end
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement