ruby - Create an Array of Fixed Length Given an Array of Arbitrary Length -


I am looking to write a method that an array of any array from a certain length (12 in my case) The line is repeated by repeating the object (although the length should always be 12 or less) is provided.

For example given to the array:

  a = [1, 2, 3, 4]  

come back to me Is:

  a = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]  

Another example:

  b = ["peach", "tail", "peer", "apple", "banana", "orange"]  
< P> will return:

, "Pear", "apple", "banana", "orange"]

and so on if an array is given with 12 objects, then it will return only to that array .

So far the methods I have written to fulfill it are very ugly and very rubei;

1.8 in

.7 & amp; 1.9 You

  a = [1,2,3,4] # = & gt; Can do good stuff with [1,2,3,4] a.cycle.take12 # = & gt; [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -