ruby - Are the elements of an array within the range of another array -
for these arrays:
array_a = [50,13,25, 35, 45] array_b = [14,45] i want know if every value in b range of values in a.
here result should true because both 14 , 45 between 13 , 50.
array_a = [50,13,25,35,45] array_b = [14,45] array_a.max >= array_b.max && array_a.min <= array_b.min # => true edit: babai's solution faster , more elegant, think.
edit: efficient solution is:
array_a = [50,13,25,35,45] array_b = [14,45] min,max = array_a.minmax array_b.all? {|num| num<=max && num>=min } # => true
Comments
Post a Comment