Skip to content
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
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