0
Ruby - Where's the error?
arr = [1,2,4,2] puts arr.minmax{|x| x%2==0}
1 Answer
+ 3
minmax method receives two arguments and the combined comparison operator (<=>) is the only accepted.
thÂĄs method return an array with two element (the min and max of array) so the correct use of the method would be:
arr.minmax { |x. y| x <=> y }
OUTPUT => [1, 4]
In this link you can check the method info
https://ruby-doc.org/core-2.6.5/Enumerable.html#method-i-minmax