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 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions function.rb
Original file line number Diff line number Diff line change
@@ -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.

method should have a more descriptive name

Choose a reason for hiding this comment

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

Could we rename this function? Maybe we could name it factorial?

Choose a reason for hiding this comment

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

Should we use more descriptive names for "function" and "n" here?

Choose a reason for hiding this comment

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

Change function to a name that tells what method does.

if n == 0

Choose a reason for hiding this comment

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

Function has no name

Choose a reason for hiding this comment

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

I agree this function needs to have a name, just as a reminder functions have:

  • name > the function name.
  • param > the name of an argument to be passed to the function. Maximum number of arguments varies in different
    engines.
  • statements> the statements which comprise the body of the function

Choose a reason for hiding this comment

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

This function is pretty short. Have you considered using a ternary?

Choose a reason for hiding this comment

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

Suggested change
if n == 0
n == 0 ? 1 : n * function(n-1)

Choose a reason for hiding this comment

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

Do we want to change this to a ternary?

1

Choose a reason for hiding this comment

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

We will likely want a return statement here.

Copy link

@cyndilopez cyndilopez Aug 15, 2019

Choose a reason for hiding this comment

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

assign to variable

else

Choose a reason for hiding this comment

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

should specify if you are returning 1 or what is happening with 1

n * function(n-1)

Choose a reason for hiding this comment

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

assign to variable

Choose a reason for hiding this comment

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

Suggested change
n * function(n-1)
return n * function(n-1)

end

Choose a reason for hiding this comment

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

Does the new value of n need to be available outside of the function? It should be saved in a variable and returned.

end

Choose a reason for hiding this comment

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

What is being returned?

Choose a reason for hiding this comment

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

Just to add , by default, functions return undefined. To return any other value, the function must have a return statement that specifies the value to return.