Answers for "merge 2 array in ruby"

1

merge two lists together ruby

# Merging
c = a + b
 => [1, 2, 3, 4, 5, 2, 4, 6]
# Removing the value of other array
# (a & b) is getting the common element from these two arrays
c - (a & b)
=> [1, 3, 5, 6]
Posted by: Guest on April-25-2021
1

concatenate arrays in ruby

array = [0, 1, 2, 3, 4]
array.concat([5, 6, 7], [8, 9, 10])
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Posted by: Guest on January-10-2022

Browse Popular Code Answers by Language