I have read that .sort, returns a sorted array while leaving the original array alone, and .sort!, modifies the actual array. but can someone explain what that actually means?
Answers to your questions
I have read that .sort, returns a sorted array while leaving the original array alone, and .sort!, modifies the actual array. but can someone explain what that actually means?
irb(main):001:0> arr = [1,3,5,4,2]
=> [1, 3, 5, 4, 2]
irb(main):002:0> arr.sort
=> [1, 2, 3, 4, 5]
irb(main):003:0> arr
=> [1, 3, 5, 4, 2]
irb(main):004:0> arr.sort!
=> [1, 2, 3, 4, 5]
irb(main):005:0> arr
=> [1, 2, 3, 4, 5]
This submission has been randomly featured in /r/serendipity, a bot-driven subreddit discovery engine. More here: https://www.reddit.com/r/Serendipity/comments/5o5nkk/someone_eli5_the_difference_between_sort_and_sort/