I am trying to solve a recursion problem.
Code:
def divide(array)
half = array.length/2
return array if array.length == 1
print ary1 = divide(array[0..half - 1])
print ary2 = divide(array[half..-1])
merge(ary1, ary2)
end
def merge(ary1, ary2)
sorted = []
end
divide([10,9,8,-300,250,1,7,6,5,4,3,2])
If I don't comment out the sorted variable, it returns a few blank arrays mixed with numbers:
[10][9][8][][][-300][250][1][][][][7][6][5][][][4][3][2][][][]
I have no idea why naming a variable (but not calling it) would result in a different output than otherwise. Any insight into this would be appreciated.