Array#concat() : concat() es un método de clase Array que devuelve la array después de unir las dos arrays.
Syntax: Array.concat() Parameter: Arrays to be combined Return: Append the two arrays
Código #1: Ejemplo para el método concat()
# Ruby code for concat() method # adding elements at the end # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [5, 4, nil, 1, 88, 9] # declaring array c = [18, 22, nil, 40, 50, 6] # COMBINING TWO ARRAYS 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"
Producción :
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]
Código #2: Ejemplo para el método concat()
# Ruby code for concat() method # adding elements at the end # declaring array a = ["abc", "xyz", "dog"] # declaring array b = ["cow", "cat", "dog"] # declaring array c = ["cat", "1", "dog"] # COMBINING TWO ARRAYS 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"
Producción :
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"]
Publicación traducida automáticamente
Artículo escrito por mayank5326 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA