Uncomplicated things

I was on the train back from the city last night when I had a thought. While doing kata04 I had hacked together something to keep track of the day and I knew there had to be a better way.

What I had done was create a variable to track the day and each time the while loop iterated it would increase the value of the variable by one, thereby keeping track of which day was lowest. Then I realized that was backwards, the day was already in the array, we just had to access it. So I changed the while loop to the one below:

while array_temp < array.length
spread = array[array_temp][1].to_i — array[array_temp][2].to_i
spread.abs
if spread < lowest_spread
lowest_spread = spread
day = array[array_temp][0]
end
array_temp += 1
end

In this case array_temp is referring to the index of the array that the day is. Since all the files are in a nested array, we use array_temp to track which array we are currently accessing data from.