0

Ruby - Where's the error?

arr = [1,2,4,2] puts arr.minmax{|x| x%2==0}

30th Sep 2019, 12:37 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
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
5th Oct 2019, 4:07 AM
Glacius