Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fp #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions test/exercise/fp/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,30 @@ class << self
# Обратиться к параметрам фильма можно так:
# film["name"], film["rating_kinopoisk"], film["rating_imdb"],
# film["genres"], film["year"], film["access_level"], film["country"]
def rating(_array)
0
def rating(array)
hash = { country: 'country', rating: 'rating_kinopoisk' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем выносить названия ключей хеша в другой хеш? Это усложнят читаемость и восприятие сейчас

count = 0
result = array.select do |film|
next unless film[hash[:rating]].to_f.positive?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не инвертируй условия, это усложняет восприятие. В руби как правило есть метод-антоним, используй их

Например, negative? — антоним positive?

next if film[hash[:rating]].to_f.negative?

Намного проще, потому что не надо в голове выполнять лишнее НЕ чтобы разобраться что делает код

next if film[hash[:country]].nil?
next unless film[hash[:country]].split(',').length >= 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже самое тут. Проще понимать условие, если меньше двух, чем если не больше или равно двум

count += 1
end
result.map { |film| film[hash[:rating]].to_f }.reduce(:+) / count
end

def chars_count(_films, _threshold)
0
def chars_count(films, threshold)
hash = { name: 'name', rating: 'rating_kinopoisk' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже самое тут, лишний код, который не добавляет понятности

count = 0
films.map do |film|
next unless film[hash[:rating]].to_f >= threshold

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже самое тут, не используй unless

arr = film[hash[:name]].split('')
count += arr.reduce(0) do |sum, char|
sum += 1 if char == 'и'
sum
end
end
count
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/exercise/fp/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Exercise::FpTest < Minitest::Test
# Посчитать средний рейтинг фильмов по версии кинопоиска у которых две или больше стран
# Фильмы у которых рейтиг не задан или равен 0 не учитывать в расчете среднего.
def test_rating
skip
array = CSV.readlines('./test/fixtures/films.csv', headers: true)

result = Exercise::Fp.rating(array)
Expand All @@ -16,7 +15,6 @@ def test_rating

# Посчитать количесвто букв 'и' в названиях всех фильмов с рейтингом кинопоиска больше или равным заданному значению
def test_chars_count
skip
array = CSV.readlines('./test/fixtures/films.csv', headers: true)

result = Exercise::Fp.chars_count(array, 5)
Expand Down
1 change: 1 addition & 0 deletions test/exercise/fp2/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class MyArray < Array

# Написать свою функцию my_each
def my_each

end

# Написать свою функцию my_map
Expand Down