ruby - Shift first 1/3 of array? -


Is there a way to turn this [1, 2, 3, 4, 5, 6, 7 , 8, 9] in this [4, 5, 6, 7, 8, 9] in a row?

Right now I am planning to specify it in one variable, getting the length, and using the shift function. It's okay, just thinking that doing this There is a more robust way for

  a = [1, 2, 3, 4, 5, 6, 7, 8, 9] a.shift (A.length / 3)    

No Change of Use

  a = [1, 2 , 3, 4, 5, 6, 7, 8, 9] one [(a.length / 3) ..-1] # = & gt; [4, 5, 6, 7, 8, 9]   

is an option that mutates and a liner

  [1, 2, 3, 4, 5, 6, 7, 8, 9]. Tap {| A. A.shift (a.length / 3)} # = & gt; [4, 5, 6, 7, 8, 9]    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -