Skip to content

Completed: arrays, fp#40

Open
bukaninandrei wants to merge 4 commits intoRestream:masterfrom
bukaninandrei:master
Open

Completed: arrays, fp#40
bukaninandrei wants to merge 4 commits intoRestream:masterfrom
bukaninandrei:master

Conversation

@bukaninandrei
Copy link

No description provided.

@snop-snov
Copy link
Collaborator

тесты в ci не прошли, нужно поправить

right = array.size
left = 0

loop do
Copy link
Collaborator

Choose a reason for hiding this comment

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

переписываем на рекурсию

sumstat = 0.0
counted = 0

for idx in 0..(array.size - 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

постарайся не использовать for, в реальной жизни он крайне редко используется. тут задачи скорее на map/reduce, можно смело использовать любые стандартные функции из арсенала массива
https://github.com/bbatsov/ruby-style-guide#no-for-loops

def chars_count(films, threshold)
counted = 0

for idx in 0..(films.size - 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

тут тоже for нужно заменить

for elem in self
yield(elem)
end
self
Copy link
Collaborator

Choose a reason for hiding this comment

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

что вернется в конце функции если не написать тут self?

# Написать свою функцию my_map
def my_map
result = MyArray.new
my_each do |elem|
Copy link
Collaborator

Choose a reason for hiding this comment

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

def my_map
result = MyArray.new
my_each do |elem|
result.append(yield(elem))
Copy link
Collaborator

Choose a reason for hiding this comment

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

не припомню метод append у массива


def test_my_compact
func = -> (element) { element if element.even? }
func_another = -> (element) { element * @int }
Copy link
Collaborator

Choose a reason for hiding this comment

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

добавь ещё вот такой assert

func_yet_another = -> (element) { element.even? }
assert @array.map(&func_yet_another).compact == @my_array.my_map(&func_yet_another).my_compact

Copy link
Author

Choose a reason for hiding this comment

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

Тест не проходит потому что из my_each возвращаются Enumerator'ы с одинаковыми элементами, но разными адресами в памяти

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