-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: master
Are you sure you want to change the base?
Conversation
def function(n) | ||
if n == 0 | ||
1 | ||
else | ||
n * function(n-1) | ||
end | ||
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.
Consider if n < 0 or n is not an integer
Worth writing a simple loop for space efficiency?
Consider adding unit tests
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.
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) |
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.
Maybe consider a more descriptive name for this function?
@@ -0,0 +1,9 @@ | |||
|
|||
def function(n) | |||
if n == 0 |
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.
what if n less than 0?
if n == 0 | ||
1 | ||
else | ||
n * function(n-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.
maybe consider explicit returns for clarity?
if n == 0 | ||
1 | ||
else | ||
n * function(n-1) | ||
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.
Consider: Ternary operator? It would make the code more readable.
@@ -0,0 +1,9 @@ | |||
|
|||
def function(n) |
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.
def function(n) | |
def factorial(n) |
Maybe this method could use a more descriptive name
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.
code looks great. could use a fix on line 3 and maybe a more descriptive function name.
@@ -0,0 +1,9 @@ | |||
|
|||
def function(n) |
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.
Consider naming the function a descriptive name to indicate what the function does
if n == 0 | ||
1 | ||
else | ||
n * function(n-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.
Consider the case where n < 1, which will cause a stack overflow
@@ -0,0 +1,9 @@ | |||
|
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.
maybe include some comments
No description provided.