Be careful, array.sort returns a new array, and will not gives you what you want.
array.sort.reverse.find { |num| num < limit } is what you are looking for, or array.sort!.reverse!.find{ |num| num < limit }, if you want to keep a sorted array. (Or even array.sort.reverse!.find { |num| num < limit } will work.)

However, "Return the first number from an Array that is less than a particular number" doesn't seem to ask for a sorted array. Maybe array.find { |num| num < limit } is enough ?

Guillaume Hivert
Ruby && Crystal Developper
LinkedIn Profile<https://fr.linkedin.com/in/ghivert>



On dc. 4 2016, at 1:10 am, Micky Scandal <mickyscandal / gmail.com> wrote:

On Sat, Dec 3, 2016 at 2:44 PM, Guillaume Hivert <guillaume.hivert / outlook.com<mailto:guillaume.hivert / outlook.com>> wrote:
"Returns the first entry for which block is not false."


OH! I must have missed that when I read through the docs. I was under the impression that it would return all entries where block is not false. so here's my solution:

def first_under(array, limit)
  array.sort.reverse!
  array.find {|num| num < limit}
end

might not be the most elegant(and if there is a better way I would like to know) but alas! it works and that's good enough (at least until I get to the re-factoring section...)
thank you thank you!
(supressed text/html)
Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>