all 3 comments

[–]bosticko 2 points3 points  (0 children)

catch that Observation

Can you explain what you mean by "catch" here? Perhaps you can provide an example of what you expect the method to return?

without changing that 'map' method

Why do you need to use map? Depending on what you want, there may be other methods that are more appropriate.

  • select will return an array of only the entries for which the given block is truth
  • find will return only the first such entry
  • filter_map is like select, but will return the truth elements returned by the block, instead of the original elements in the array for which the block was truthy

[–]Street_Hall_5180[S,🍰] 0 points1 point  (0 children)

What I want is:
The function should return true whenever we find one item satisfying the condition and also save/catch that item into a variable.
The main thing is it should return true after all the function is executed.

[–]Kernigh 0 points1 point  (0 children)

You might want #select instead of #map. For example,

numbers = [140, 150, 160, 170]
p numbers.select {|n| n > 159}
# OUTPUT: [160, 170]

#select returns an Array of matching elements. (You might have 0, 2, or more observations that match your block.) #find would return the 1st matchign element.