标签: arrays ruby
给定数组
["zone", "abigail", "theta", "form", "libe", "zas"]
是否有一种简单的方法可以通过数组并将字符串组合成对,因此......
["zoneabigail", "abigailtheta", "thetaform", "formlibe", "libezas"]
答案 0 :(得分:7)
您正在搜索Enumerable#each_cons:
Enumerable#each_cons
words.each_cons(2).map(&:join)