Hello! Recently I began to study ruby, I decide homework:
In the csv file, the temperature indicators for each day are displayed in the form of:
30.01, -7 31.01, -10 01.02, 0 ...etc
Parse the file, calculate and display the average temperature for each month. Code verification via rubocop
CSV.read('/home/natasha/Документы/CSV/temperature.csv') #вывожу даные из csv файла в irb консоль #наверное это не очень правильно, но не знаю, как обратиться к массиву array = [["1.01", "0"], ["2.01", "4"], ["3.01", "1"], ["4.01", "0"], ["5.01", "3"], ["6.01", "-12"], ["7.01", "-14"], ["8.01", "-8"], ["9.01", "-3"], ["10.01", "-1"], ["11.01", "-5"], ["12.01", "-5"], ["13.01", "4"], ["14.01", "2"], ["15.01", "-3"], ["16.01", "-7"], ["17.01", "-6"], ["18.01", "-7"], ["19.01", "-2"], ["20.01", "0"], ["21.01", "0"], ["22.01", "0"], ["23.01", "-2"], ["24.01", "-3"], ["25.01", "-9"], ["26.01", "-4"], ["27.01", "-4"], ["28.01", "-3"], ["29.01", "-9"], ["30.01", "-8"], ["31.01", "-8"], ["1.02", "-6"], ["2.02", "-3"], ["3.02", "-1"], ["4.02", "1"], ["5.02", "-2"], ["6.02", "-5"], ["7.02", "-10"], ["8.02", "-12"], ["9.02", "-7"], ["10.02", "-6"], ["11.02", "-5"], ["12.02", "-5"], ["13.02", "-3"], ["14.02", "0"], ["15.02", "1"], ["16.02", "1"], ["17.02", "1"], ["18.02", "4"], ["19.02", "2"], ["20.01", "1"], ["21.02", "4"], ["2.02", "6"], ["23.02", "5"], ["24.02", "12"], ["25.02", "2"]] array1 = array.flatten #"сплющиваю массив" #=>["1.01", "0", "2.01", "4", "3.01", "1", "4.01", "0", "5.01", "3", "6.01", "-12", "7.01", "-14", "8.01", "-8", "9.01", "-3", "10.01", "-1", "11.01", "-5", "12.01", "-5", "13.01", "4", "14.01", "2", "15.01", "-3", "16.01", "-7", "17.01", "-6", "18.01", "-7", "19.01", "-2", "20.01", "0", "21.01", "0", "22.01", "0", "23.01", "-2", "24.01", "-3", "25.01", "-9", "26.01", "-4", "27.01", "-4", "28.01", "-3", "29.01", "-9", "30.01", "-8", "31.01", "-8", "1.02", "-6", "2.02", "-3", "3.02", "-1", "4.02", "1", "5.02", "-2", "6.02", "-5", "7.02", "-10", "8.02", "-12", "9.02", "-7", "10.02", "-6", "11.02", "-5", "12.02", "-5", "13.02", "-3", "14.02", "0", "15.02", "1", "16.02", "1", "17.02", "1", "18.02", "4", "19.02", "2", "20.01", "1", "21.02", "4", "2.02", "6", "23.02", "5", "24.02", "12", "25.02", "2"] Do not judge strictly. Help, please tell me the right way. I just do not know how to do next. I thought I could get whole numbers from an array, and then calculate the arithmetic average of them. In general, to be honest, I'm confused, I have been sitting for the second day and can’t think of anything.