Q:

Write a Ruby program to iterate over the first n elements of a given array

0

Write a Ruby program to iterate over the first n elements of a given array. 

All Answers

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

arra1 = ['abcde', 'abdf', 'adeab', 'abdgse', 'bdefa', 'bacdef']
print "Original array:\n"
print arra1
arra2 = arra1.first(3)
print "\nFirst 3 elements:\n"
print arra2

Output:

Original array:
["abcde", "abdf", "adeab", "abdgse", "bdefa", "bacdef"]
First 3 elements:
["abcde", "abdf", "adeab"]

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