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]
Written by Fab Mackojc
Related protips
2 Responses
awesome!
over 1 year ago
·
Great trick
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#