'undefined method `>' for [1000, []]:Array (NoMethodError)
am trying to read the files of months for a year. In files there are some empty values. am trying to compare value of array (which i read from file) with default value but i keep getting the following error:
undefined method `>' for [1000, []]:Array (NoMethodError)
i checked the class of value which am getting from file it's integer but why then it's showing this error
def monthly_temperature(file_data)
highest_temp = max_humdity = 0
lowest_temp = 100 , info = []
array = file_data.map { |string| string.split(',') }
array.each_with_index do |days, ind|
array[ind].shift() #removing every first index
if highest_temp < array[ind].first.to_i
highest_temp = array[ind].first.to_i
end
a = array[ind].fetch(2).to_i
#puts a.class
if lowest_temp > a
lowest_temp = a
end
end
end
Solution 1:[1]
Your javascript-like assignment:
lowest_temp = 100 , info = []
is equivalent to
lowest_temp = [100, info = []]
resulting lowest_temp holding an array. Correct parallel assignment is done like this:
lowest_temp, info = 100, []
Generally it should be only used when destructuring an array or when assigned values have a similar meaning (and assigning them together makes code easier to understand). In all the other cases, regular assignment is preferable for readability:
lowest_temp = 100
info = []
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
