0
RuBy. Why the code behaves this way?
Need explanation RUBY https://code.sololearn.com/cXg32HZbZ5Wr/?ref=app
4 Respuestas
+ 5
Can you please put your code in playground and link it here? Thanks!
+ 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
+ 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. 😁
0
Done, see above...thank you