Ruby Array Exercises: Iterate over the first n elements of a given array
Ruby Array: Exercise-47 with Solution
Write a Ruby program to iterate over the first n elements of a given array.
arra1 = ['abcde', 'abdf', 'adeab', 'abdgse', 'bdefa', 'bacdef'] print "Original array:\n" print arra1 arra2 = arra1.first(3) print "\nFirst 3 elements:\n" print arra2
Original array: ["abcde", "abdf", "adeab", "abdgse", "bdefa", "bacdef"] First 3 elements: ["abcde", "abdf", "adeab"]
Ruby Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework