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?
You can use a range for the array index to accomplish this easily:
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.