GhostRider
GhostRider

Reputation: 2170

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"]

Upvotes: 1

Views: 124

Answers (1)

ndnenkov
ndnenkov

Reputation: 36110

You are searching for Enumerable#each_cons:

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

Upvotes: 7

Related Questions