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,?
···
--
Posted via http://www.ruby-forum.com/.
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,?
--
Posted via http://www.ruby-forum.com/.
Why is that a requirement?
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.
--
Lars Haugseth
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):
http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-max_by
words = [
'a',
'abc',
'abcde',
'ab'
]
puts words.max_by &:length
--
Posted via http://www.ruby-forum.com/.
Suggested reading is on Blocks, Procs and Lambdas: http://bit.ly/NGQTjT
Have a nice day,
Brandon Weaver
On Fri, Sep 21, 2012 at 7:16 AM, Jan E. <lists@ruby-forum.com> wrote:
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):http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-max_by
words = [
'a',
'abc',
'abcde',
'ab'
]
puts words.max_by &:length--
Posted via http://www.ruby-forum.com/.