+ 2
Challenge question Explanation? (Ruby)
What is the output of this code? puts "sololearn".delete("sol"<<"cash" the answer is earncash. But I don't get it. I can memorize the answer but it would not help in understanding.
4 Answers
+ 2
Thank you Faisal
+ 2
Thank you John Wells.
+ 1
delete removes all occurrences of the specified characters so "abcdeffedcba".delete("ae") yields "bcdffdcb".
https://code.sololearn.com/cVqfxCl6E4cb
- 1
I'm not exactly the best at Ruby, but it seems that the program is deleting any substring within the string 'sololearn' that consists of 'sol'. I think it may be deleting the second 'ol' because it is connected to the first 'sol' and consists of a substring within the string 'sol' (again, I'm not exactly the best at Ruby so that may be wrong). Then, once it deletes 'solol', it pushes 'cash' to the end of the string therefore resulting in 'earncash'.