I would like to substitute Ruby's maximum and minimum values and p as a conditional branch.

Asked 2 years ago, Updated 2 years ago, 31 views

A2=34.773381
A3 = 135.542685

A = 34.774974
B = 34.774551
C = 34.774323
D = 34.774625

A1 = 135.541896
B1 = 135.542218
C1 = 135.541641
D1 = 135.541393

# I would like to substitute W, X, Y, and Z for the maximum and minimum values shown here for conditional branching.
array1 = [A, B, C, D]
array1.max
array1.min

array2 = [A1, B1, C1, D1 ]
array2.max
array2.min

if(A2>W)then
  if(A2<X)then
    if(A2>Y)then
      if(A2<Z)then
        print "Failed\n"
      else
        print "Success\n"
      end
    end
  end
end

ruby

2022-09-29 22:42

1 Answers

If you break down the array.max, the array.max returns the maximum value of the list, and the p argument is the detailed output of the argument, so in this example, you just need to replace it with a variable.

array1=[A,B,C,D]
W = array1.max
X = array 1.min

array2 = [A1, B1, C1, D1 ]
Y = array2.max
Z=array2.min


2022-09-29 22:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.