Ruby Array Exercises: Concatenate array of arrays into one
Ruby Array: Exercise-16 with Solution
Write a Ruby program to concatenate array of arrays into one.
Ruby Code:
fnums = [ 10, 20, [30, [40, 50] ] ]
print "Original array:\n"
print fnums
nums = fnums.flatten
print "\nFlatten array:\n"
print nums
Output:
Original array: [10, 20, [30, [40, 50]]] Flatten array: [10, 20, 30, 40, 50]
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to create an array of length 2 containing their middle elements from two given arrays of integers and length 3.
Next: Write a Ruby program to check whether an given array of integers of length 2 contains a 4 or a 7.
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://w3resource.com/ruby-exercises/array/ruby-array-exercise-16.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics