I have an array of arbitrary elements, say strings:
testArray = {"String A", "String B", "String C", "String D", "String E"};
How can I split this into two arrays, one for the element with odd indices in testArray
and one for elements with even indices in testArray
:
testArrayOdd = {"String A", "String C", "String E"};
testArrayEven = {"String B", "String D"};
Is there a simple way to do this that generalizes to more complicated partitionings based on, say, the primeness of the index?
Clarification!: The strings in the array can be anything "String 1" could be "knejibvei (junk)". We only care about the INDEX of the string in the original array. Sorry about this. For odd / even testing of elements, see here: Separate an array in two arrays, the even and odd terms being separated in these two arrays