Skip to content
Open

Fp #41

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
18 changes: 16 additions & 2 deletions test/exercise/arrays/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ module Exercise
module Arrays
class << self
def replace(array)
array
array.map { |el| el.positive? ? array.max : el }
end

def search(_array, _query)
0
max = _array.length - 1
min = 0

while min <= max
mid = (min + max) / 2
if _array[mid] == _query
return mid
elsif _array[mid] > _query
max = mid - 1
else
min = mid + 1
end
end

-1
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/exercise/arrays/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Exercise::ArraysTest < Minitest::Test
# Заменить все положительные элементы целочисленного массива на максимальное значение элементов массива.
def test_replace
skip

array = [3, 2, -8, 4, 100, -6, 7, 8, -99]
new_array = Exercise::Arrays.replace(array)

Expand All @@ -14,7 +14,7 @@ def test_replace
# Реализовать двоичный поиск
# Функция должна возвращать индекс элемента
def test_bin_search
skip

assert Exercise::Arrays.search([1], 900) == -1
assert Exercise::Arrays.search([1], 1).zero?
assert Exercise::Arrays.search([], 900) == -1
Expand Down
11 changes: 9 additions & 2 deletions test/exercise/fp/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ class << self
# film["name"], film["rating_kinopoisk"], film["rating_imdb"],
# film["genres"], film["year"], film["access_level"], film["country"]
def rating(_array)
0
_array = _array.map { |film| film if film['country'] }.compact
_array = _array.map { |film| film if film['rating_kinopoisk'] }.compact
_array = _array.map { |film| film['rating_kinopoisk'].to_f if film['country'].split(',').size > 1 }.compact
_array = _array.map { |rate| rate if rate.positive? }.compact
_array.reduce { |sum, el| sum + el }.to_f / _array.size
end

# Посчитать количесвто букв 'и' в названиях всех фильмов с рейтингом кинопоиска больше или равным заданному значению

def chars_count(_films, _threshold)
0
_films = _films.map { |film| film['name'].count('и') if film['rating_kinopoisk'].to_f > _threshold }.compact
_films.reduce { |sum, el| sum + el }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/exercise/fp/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 @@ -18,7 +18,7 @@ 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