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

PR-2: function method added #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

PR-2: function method added #2

wants to merge 1 commit into from

Conversation

CheezItMan
Copy link

No description provided.

Comment on lines +2 to +8
def function(n)
if n == 0
1
else
n * function(n-1)
end
end
Copy link

@geneminde geneminde Mar 11, 2021

Choose a reason for hiding this comment

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

Consider if n < 0 or n is not an integer

Worth writing a simple loop for space efficiency?

Consider adding unit tests

Choose a reason for hiding this comment

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

Suggested change
def function(n)
if n == 0
1
else
n * function(n-1)
end
end
def function(n)
if n == 0
1
else
n * function(n-1)
end
end

Can you make it more clear what this function is attempting to do?

@@ -0,0 +1,9 @@

def function(n)

Choose a reason for hiding this comment

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

Maybe consider a more descriptive name for this function?

@@ -0,0 +1,9 @@

def function(n)
if n == 0

Choose a reason for hiding this comment

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

what if n less than 0?

if n == 0
1
else
n * function(n-1)
Copy link

Choose a reason for hiding this comment

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

maybe consider explicit returns for clarity?

Comment on lines +3 to +7
if n == 0
1
else
n * function(n-1)
end
Copy link

@lina5147 lina5147 Mar 11, 2021

Choose a reason for hiding this comment

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

Consider: Ternary operator? It would make the code more readable.

@@ -0,0 +1,9 @@

def function(n)

Choose a reason for hiding this comment

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

Suggested change
def function(n)
def factorial(n)

Maybe this method could use a more descriptive name

Copy link

@jwinchan jwinchan left a comment

Choose a reason for hiding this comment

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

code looks great. could use a fix on line 3 and maybe a more descriptive function name.

@@ -0,0 +1,9 @@

def function(n)

Choose a reason for hiding this comment

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

Consider naming the function a descriptive name to indicate what the function does

if n == 0
1
else
n * function(n-1)

Choose a reason for hiding this comment

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

Consider the case where n < 1, which will cause a stack overflow

@@ -0,0 +1,9 @@

Copy link

Choose a reason for hiding this comment

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

maybe include some comments

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.

8 participants