On Sat, Dec 3, 2016 at 11:28 PM, Micky Scandal <mickyscandal / gmail.com> wrote:

> Return the first number from an Array that is less than a particular number
> - 'limit.' You should make use of Enumerable#find

That is a different problem to solve than the one described in the
subject. So which is it that you want to solve?

> and then gives me this code to work with:
>
> def first_under(array, limit)
>
> end
>
> puts first_under([13, 21, 7, 0, 11, 106], 10) == 7

From the name of the method it seems your subject is wrong and you are
really seeking the first number less than the limit. But your first
solution posted rather tries to implement the subject. I think
Guiilaume's solution is spot on:

array.find { |num| num < limit }

This is a nice illustration how important it is to *first* clarify
what problem to solve before coding solutions.

Kind regards

robert


-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>