Skip to content

HomeWork2#2

Open
abercromb wants to merge 2 commits intomasterfrom
lesson2
Open

HomeWork2#2
abercromb wants to merge 2 commits intomasterfrom
lesson2

Conversation

@abercromb
Copy link
Owner

No description provided.

//1.Написать функцию, которая определяет, четное число или нет.

func isEven(_ number: Int) -> Bool {
return number % 2 == 0 ? true : false;
Copy link

Choose a reason for hiding this comment

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

можно скоратить до return number % 2 == 0


for(index, value) in tArray.enumerated(){
if isEven(value) || !function2(value) {
tArray.remove(at: tArray.firstIndex(of: value)!);
Copy link

Choose a reason for hiding this comment

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

tArray.firstIndex(of: value)? Ты ведь уже index получаешь

return 1;
}

return fibonacci(n - 1) + fibonacci(n - 2);
Copy link

Choose a reason for hiding this comment

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

рекурсивная функция считается не очень оптимальной. Посмотри есть материалы, что при достаточно большом числе все пойдет по....ну ты знаешь:)
Есть варианты с мемоизацией


//2. Написать функцию, которая определяет, делится ли число без остатка на 3.

func function2(_ number: Int) -> Bool{
Copy link

Choose a reason for hiding this comment

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

давай имена фукнциям более осмысленные
типа isDivisionByThree()

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