Merge and interleave two arrays in Ruby

后端 未结 11 2102
猫巷女王i
猫巷女王i 2020-12-04 07:34

I have the following code:

a = [\"Cat\", \"Dog\", \"Mouse\"]
s = [\"and\", \"&\"]

I want to merge the array s into array <

11条回答
  •  一向
    一向 (楼主)
    2020-12-04 08:01

    If you don't want duplicate, why not just use the union operator :

    new_array = a | s
    

提交回复
热议问题