+ 1
Ruby - What does this code do?
And why output is 1,2,3? arr = [1,2,3] puts arr.each{ |x| x = -x}
1 Answer
0
I'm not sure what exactly you want
if you want the output to be negative.
It should be
arr.each{ |x| puts -x}
not
puts arr.each{ |x| x = -x}