Last Updated: July 26, 2022
·
43.13K
· fabsays

Swap two elements of an array in Ruby

array = [4, 5, 6, 7]

array[0], array[3] = array[3], array[0]

array # => [7, 5, 6, 4]

2 Responses
Add your response

awesome!

over 1 year ago ·

Great trick

over 1 year ago ·