Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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 Array Exercises: 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:

Flowchart: Concatenate array of arrays into one

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?