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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -