Ruby .sort method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ruby .sort method

I am doing challenge in ruby What's the output of this code? arr = ["baa", "aba", "aab"] arr.sort print arr [0] ---------- the answer is "baa" But as far as I understand .sort it should be "aab". Please explain if I am wrong.

14th Oct 2019, 5:09 PM
LenaK
LenaK - avatar
1 Answer
+ 1
documentation usually help in this case. sort is returning a new array, but not altering the array itself. sort! do
14th Oct 2019, 5:17 PM
Taste
Taste - avatar