2009/2/18 7stud -- <bbxx789_05ss / yahoo.com>:
> Andy Elvey wrote:
>>
>
> arr1 = [1, 2, 3, 4, 5]
> arr2 = ["foo", "bar", "baz", "abc", "def"]
>
> resultA = arr1.zip(arr2).flatten
>
> resultB = []
> arr2.each do |item|
>  resultB << "|" << item
> end
> resultB << "|"
>
You can also write it using inject like this:
arr = arr2.inject(["|"]){|r,e|r<<e<<"|"}

> resultC = []
> arr2.each do |item|
>  resultC << item << "|"
> end
> resultC.pop()
>
arr = arr2.inject([]){|r,e|r<<e<<"I"}
arr.pop

Regards,

Park Heesob