Mix up an array
array = [1,2,3,4,5]
new_array = []
front_index = 0
back_index = array.length-1
while front_index <= back_index
new_array << array[front_index]
front_index += 1
if front_index <= back_index
new_array << array[back_index]
back_index -= 1
end
end
p new_array # => [1, 5, 2, 4, 3]
Related examples in the same category