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

Pr-2 #2

wants to merge 1 commit into from

Conversation

CheezItMan
Copy link

This method calculates a factorial

@CheezItMan CheezItMan changed the title function method added Pr-2 Aug 13, 2019
@@ -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.

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

else
n * function(n-1)
end
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.


def function(n)
if n == 0
1
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

def function(n)
if n == 0
1
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

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.

assign to variable

Copy link

@cyndilopez cyndilopez left a comment

Choose a reason for hiding this comment

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

needs work

@@ -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.

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

Copy link

@griffifam griffifam left a comment

Choose a reason for hiding this comment

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

function name 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.

Change function to a name that tells what method does.

Copy link

@MariaWissler MariaWissler left a comment

Choose a reason for hiding this comment

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

Lets double check this code, let us know once you submit your updates

@@ -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.

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

else
n * function(n-1)
end
end

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.

@@ -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.

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

@@ -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.

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


def function(n)
if n == 0
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.

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.

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

1
else
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.

@@ -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

@@ -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.

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

@@ -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.

Do we want to change this to a ternary?

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.

10 participants