Ruby | Array concat() operation
Array#concat() : concat() is a Array class method which returns the array after appending the two arrays together.
Syntax: Array.concat()
Parameter: Arrays to be combined
Return: Append the two arrays
Code #1 : Example for concat() method
a = [ 18 , 22 , 33 , nil , 5 , 6 ]
b = [ 5 , 4 , nil , 1 , 88 , 9 ]
c = [ 18 , 22 , nil , 40 , 50 , 6 ]
puts "combining a and b : #{a.concat(b)}\n\n"
puts "combining c and b : #{b.concat(c)}\n\n"
puts "combining a and c : #{c.concat(a)}\n\n"
|
Output :
combining a and b : [18, 22, 33, nil, 5, 6, 5, 4, nil, 1, 88, 9]
combining c and b : [5, 4, nil, 1, 88, 9, 18, 22, nil, 40, 50, 6]
combining a and c : [18, 22, nil, 40, 50, 6, 18, 22, 33, nil, 5, 6, 5, 4, nil, 1, 88, 9]
Code #2 : Example for concat() method
a = [ "abc" , "xyz" , "dog" ]
b = [ "cow" , "cat" , "dog" ]
c = [ "cat" , "1" , "dog" ]
puts "combining a and b : #{a.concat(b)}\n\n"
puts "combining c and b : #{b.concat(c)}\n\n"
puts "combining a and c : #{c.concat(a)}\n\n"
|
Output :
combining a and b : ["abc", "xyz", "dog", "cow", "cat", "dog"]
combining c and b : ["cow", "cat", "dog", "cat", "1", "dog"]
combining a and c : ["cat", "1", "dog", "abc", "xyz", "dog", "cow", "cat", "dog"]
Last Updated :
08 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...