Helpppp head hurt and i m about to beat this sit up

newarray =[]

sum = 0
i = 0

while i < data.length
val1 = data[i]
j = i+1
while j < data.length
val2 = data[j]
sum = val2 + val1

newarray << val2 if sum == 0
newarray << val1 if sum == 0

j = j+1

i = i+1


p newarray

#comment. the above give me the right answer which is -1 and 1…but it
doesnt give me 3 and -3…i need 3 and -3 also…how i do that
#comment. so it stop after finding the first two numbers that add to
zero…how do i make it keep going till the end of array…it should
include 3 and -3.

I think you meant to have one of the 3s be positive in your data array


same code gave me this result [-1, 1, -3, 3]

thanks man lol…i slept at 3am last nite…

That’s nothing dude, must of us don’t sleep, just coffee coffee

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs