Skip to content

Conversation

@AndreyChim
Copy link

No description provided.

Comment on lines 5 to 8
max = array[0]
array.each do |i|
max = i if i >= max
end
Copy link

Choose a reason for hiding this comment

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

вынеси поиск максимума вотдельный метод

right = array.length - 1
left = 0

while left <= right
Copy link

Choose a reason for hiding this comment

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

нужно использовать рекурсию

Copy link
Author

Choose a reason for hiding this comment

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

можно в функцию добавить новый параметр ?, например, счетчик, если да, то его также надо добавить в test.rb

Copy link

Choose a reason for hiding this comment

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

можно добавить, но так, чтобы не править тесты. Посмотри про аргументы со значением по умолчанию или с ключевым словом


while left <= right
mid = (left + right) / 2
if array[mid] == query
Copy link

Choose a reason for hiding this comment

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

guard clause + тернарный

def search(_array, _query)
0
def search(array, query)
right = array.length - 1
Copy link

Choose a reason for hiding this comment

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

это можно перенести в 12 строку

@AndreyChim AndreyChim force-pushed the exercise branch 2 times, most recently from cce68b6 to 700f4b8 Compare March 1, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants