I have an array in Ruby that looks like this:
[ 0] "Red",
[ 1] "Green",
[ 2] "Blue",
[ 3] "Yellow",
[ 4] "Cyan",
[ 5] "Magenta",
[ 6] "Orange",
[ 7] "Purple",
[ 8] "Pink",
[ 9] "White",
[10] "Black"
I need to search for the values between say Yellow and Purple and rebuild the array so that it looks something like this:
[ 0] "Red",
[ 1] "Green",
[ 2] "Blue",
[ 3] [[0] "Cyan",[1] "Magenta",[2] "Orange" ],
[ 4] "Cyan",
[ 5] "Magenta",
[ 6] "Orange",
[ 7] "Purple",
[ 8] "Pink",
[ 9] "White",
[10] "Black"
Is there an easy way to this in Ruby?
1 Answer