-
Notifications
You must be signed in to change notification settings - Fork 92
Add def to max & find #43
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
base: main
Are you sure you want to change the base?
Conversation
| max = array[0] | ||
| array.each do |i| | ||
| max = i if i >= max | ||
| end |
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.
вынеси поиск максимума вотдельный метод
test/exercise/arrays/solution.rb
Outdated
| right = array.length - 1 | ||
| left = 0 | ||
|
|
||
| while left <= right |
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.
нужно использовать рекурсию
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.
можно в функцию добавить новый параметр ?, например, счетчик, если да, то его также надо добавить в test.rb
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.
можно добавить, но так, чтобы не править тесты. Посмотри про аргументы со значением по умолчанию или с ключевым словом
test/exercise/arrays/solution.rb
Outdated
|
|
||
| while left <= right | ||
| mid = (left + right) / 2 | ||
| if array[mid] == query |
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.
guard clause + тернарный
test/exercise/arrays/solution.rb
Outdated
| def search(_array, _query) | ||
| 0 | ||
| def search(array, query) | ||
| right = array.length - 1 |
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.
это можно перенести в 12 строку
cce68b6 to
700f4b8
Compare
No description provided.