You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
312 B
12 lines
312 B
1 month ago
|
def task1(array)
|
||
|
indices = array.each_with_index.to_a
|
||
|
sorted_indices = indices.sort_by { |(element, index)| -element }
|
||
|
result = sorted_indices.map { |(element, index)| index }
|
||
|
result
|
||
|
end
|
||
|
|
||
|
# Ex
|
||
|
array = [5, 3, 8, 1, 7]
|
||
|
puts "Indices in order of decreasing elements:"
|
||
|
puts task1(array).join(", ")
|