I am confusing about Proc and lambdas.
I need to just find out the longest word in the given array using Proc
or lambda.
Can any one post the code,?
I am confusing about Proc and lambdas.
I need to just find out the longest word in the given array using Proc
or lambda.
Can any one post the code,?
On 09/21/2012 11:38 AM, Venkat Ch wrote:
I am confusing about Proc and lambdas.
I need to just find out the longest word in the given array using Proc
or lambda.
Why is that a requirement?
Hi,
This is not a homework forum. Apart from that, your description is far
too vague to make anything useful out of it. Procs are just a tool, you
can use them in all kinds of ways. So saying “find the word using a
proc” is like saying “sort an array using methods”.
The usual solution to “get the smallest/biggest value” is to use the
method Enumerable#max_by (or min_by):
words = [
‘a’,
‘abc’,
‘abcde’,
‘ab’
]
puts words.max_by &:length
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs