Ruby-on-rails – How to find the maximum position in the array?

If I have

ary = [7, 8, 0, 1, nil, 6]

How to find the position of the maximum value in the array? I can do this, but it needs more than one line.

This will return the first in the array Index of the maximum value:

ary = [7, 8, 0, 1, nil, 6, 8]
ary.index(ary. compact.max)
=> 1

If I have

ary = [7 , 8, 0, 1, nil, 6]

How to find the position of the maximum value in the array? I can do this, but it requires more than one line.

This will return the index of the first largest value in the array:

ary = [7, 8, 0, 1, nil, 6, 8]
ary.index(ary.compact.max)
=> 1< /pre>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3334 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.