0

RuBy. Why the code behaves this way?

Need explanation RUBY https://code.sololearn.com/cXg32HZbZ5Wr/?ref=app

14th Jun 2020, 10:02 AM
IrinaKW
IrinaKW - avatar
4 odpowiedzi
+ 5
Can you please put your code in playground and link it here? Thanks!
14th Jun 2020, 10:21 AM
Lothar
Lothar - avatar
+ 4
I am not sure what you want to achieve, but i have modified your code slightly: arr=[1,-2,3] arr.each{|x| puts x=-x} # this does change the sign of the numbers arr=[1,-2,3] arr.each{|x| puts x-=1} # this does subtract 1 from each element in arr
14th Jun 2020, 1:28 PM
Lothar
Lothar - avatar
+ 1
Thank you Lothar I'm not trying to achieve anything per se; just to understand how x=-x and x=x or just x will puts the same result. It was the question in one of the challenges. 😁
14th Jun 2020, 2:03 PM
IrinaKW
IrinaKW - avatar
0
Done, see above...thank you
14th Jun 2020, 11:38 AM
IrinaKW
IrinaKW - avatar