Ruby Array Exercises: Iterate an array starting from the last element
Ruby Array: Exercise-46 with Solution
Write a Ruby program to iterate an array starting from the last element.
Ruby Code:
nums = [10, 20, 30, 40, 10, 10, 20]
print "Original array:\n"
print nums
print "\nReverse array:\n"
nums.reverse.each { |x| puts x }
Output:
Original array: [10, 20, 30, 40, 10, 10, 20] Reverse array: 20 10 10 40 30 20 10
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to search items start with specified string of a given array.
Next: Write a Ruby program to iterate over the first n elements of a given array.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/ruby-exercises/array/ruby-array-exercise-46.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics