Lets say I have the following array:
array_sample = [2, 7, 3, -5, 2, -6]
Is there a method to replace '-5' and '-6' with 0 (or any other potential negative values)?
I have tried the following which does not seem to work:
for i in array_sample
if array_sample[i] < 0
array_sample[i] = 0
end
Any suggestions would be appreciated, because this seems very simple!
i
is not what you think it is. Just insertputs i
belowfor i in array_sample
to investigate..map
or.each
than for loops in ruby: stackoverflow.com/a/31263749/8031815