Question: I have arrays like this:

```
myArr = [a,b,c,d,e,f,g]
myArr = [a]
myArr = [a,b,c]

```

**How can I break up the arrays such that:**

Variable `first_portion` has the **first 3 items** and `rest_portion` **has all remaining ones**?

If an array has 3 or less items, I'd like rest\_portion to contain nil so that I can check for it in logic.

**Any advise?**

Answer: 
You can use a range for the array index to accomplish this easily:

```
first_portion = myArr[0..2]
rest_portion = myArr[3..-1]

```

If the range partially overlaps the range, you'll get an array with only as many items as are available. If the range has no overlap with the array, you'll get nil.

```
[a,b,c,d,e,f,g][0..2]
#=> [a, b, c]
[a,b,c,d,e,f,g][3..-1]
#=> [d,e,f,g]

[a][0..2]
#=> [a]
[a][3..-1]
#=> nil

```
```
>> myArr = %w|a b c d e f g|
=> ["a", "b", "c", "d", "e", "f", "g"]
>> first_portion, rest_portion = myArr[0, 3], myArr[3..-1].nil? ? nil : myArr[3..-1].empty? ? nil : myArr[3..-1]
=> [["a", "b", "c"], ["d", "e", "f", "g"]]

>> first_portion
=> ["a", "b", "c"]
>> rest_portion
=> ["d", "e", "f", "g"]

>> myArr = %w|a|
=> ["a"]
>> first_portion, rest_portion = myArr[0, 3], myArr[3..-1].nil? ? nil : myArr[3..-1].empty? ? nil : myArr[3..-1]
=> [["a"], nil]

>> first_portion
=> ["a"]
>> rest_portion
=> nil

>> myArr = %w|a b c|=> ["a", "b", "c"]
>> first_portion, rest_portion = myArr[0, 3], myArr[3..-1].nil? ? nil : myArr[3..-1].empty? ? nil : myArr[3..-1]
=> [["a", "b", "c"], nil]

>> first_portion
=> ["a", "b", "c"]
>> rest_portion
=> nil

```