-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Feature/fp #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' } | ||
count = 0 | ||
result = array.select do |film| | ||
next unless film[hash[:rating]].to_f.positive? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не инвертируй условия, это усложняет восприятие. В руби как правило есть метод-антоним, используй их Например,
Намного проще, потому что не надо в голове выполнять лишнее |
||
next if film[hash[:country]].nil? | ||
next unless film[hash[:country]].split(',').length >= 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ class MyArray < Array | |
|
||
# Написать свою функцию my_each | ||
def my_each | ||
|
||
end | ||
|
||
# Написать свою функцию my_map | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем выносить названия ключей хеша в другой хеш? Это усложнят читаемость и восприятие сейчас