GhostRider GhostRider - 1 month ago 5
Ruby Question

Ruby:concatenate pairs of strings in an array

Given the array

["zone", "abigail", "theta", "form", "libe", "zas"]


Is there a straightforward way to go through the array and combine the strings into pairs, thus...

["zoneabigail", "abigailtheta", "thetaform", "formlibe", "libezas"]

ndn ndn
Answer

You are searching for Enumerable#each_cons:

words.each_cons(2).map(&:join)
Comments