Q:

Write a Ruby program to create a new array with the elements in reverse order from a given an array of integers length 3

0

Write a Ruby program to create a new array with the elements in reverse order from a given an array of integers length 3.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_array(nums)
    reversed = nums[2], nums[1], nums[0]
	return reversed;
end

print check_array([1, 2, 5]),"\n" 
print check_array([1, 2, 3]),"\n" 
print check_array([1, 2, 4])  

Output:

[5, 2, 1]
[3, 2, 1]
[4, 2, 1]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now