ruby - Shift first 1/3 of array? -
Is there a way to turn this Right now I am planning to specify it in one variable, getting the length, and using the No Change of Use is an option that mutates and a liner [1, 2, 3, 4, 5, 6, 7 , 8, 9] in this
[4, 5, 6, 7, 8, 9] in a row?
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)
a = [1, 2 , 3, 4, 5, 6, 7, 8, 9] one [(a.length / 3) ..-1] # = & gt; [4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]. Tap {| A. A.shift (a.length / 3)} # = & gt; [4, 5, 6, 7, 8, 9]
Comments
Post a Comment