tuples
This commit is contained in:
parent
c0244b5822
commit
61dc873489
5 changed files with 60 additions and 5 deletions
29
test/ruby/26.out
Normal file
29
test/ruby/26.out
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
def find_max_min(numbers)
|
||||
if not numbers
|
||||
return [None, None]
|
||||
end
|
||||
max_num = numbers[0]
|
||||
min_num = numbers[0]
|
||||
for num in numbers[1...-1]
|
||||
if num > max_num
|
||||
max_num = num
|
||||
end
|
||||
if num < min_num
|
||||
min_num = num
|
||||
end
|
||||
end
|
||||
return [max_num, min_num]
|
||||
end
|
||||
def reverse_list(items)
|
||||
reversed_items = []
|
||||
for i in (items.length - 1...- 1).step(- 1)
|
||||
reversed_items.append(items[i])
|
||||
end
|
||||
return reversed_items
|
||||
end
|
||||
numbers = [3, 1, 4, 1, 5, 9, 2, 6]
|
||||
max_val, min_val = find_max_min(numbers)
|
||||
print("List: #{numbers}", "\n")
|
||||
print("Max: #{max_val}, Min: #{min_val}", "\n")
|
||||
print("Reversed: #{reverse_list(numbers)}", "\n")
|
||||
print("Original list unchanged: #{numbers}", "\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue