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

Ports - Margaret #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Ports - Margaret #14

wants to merge 3 commits into from

Conversation

msfinnan
Copy link

@msfinnan msfinnan commented Apr 9, 2019

No description provided.

Copy link

@mmcknett mmcknett left a comment

Choose a reason for hiding this comment

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

Good job! This solution looks great overall, minus some minor nits.

Checklist

  • Clean, working code
    • Works just fine!
    • The minor formatting issues and the variable naming are detracting from the cleanliness of this solution.
  • Efficient code - give feedback as you would give to a peer on your team
  • A detailed explanation of time and space complexity (explains what n stands for, explains why it would be a specific complexity, etc.)
    • Be sure to briefly explain your time and space complexity analyses.
  • All test cases for the assignment should be passing.

# Time complexity: ?
# Space complexity: ?
# Time complexity: Linear or O(n) where n is the number input
# Space complexity: Constant or O(1), will have the same number of variables no matter the size of the input

Choose a reason for hiding this comment

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

I like this concise explanation for the space complexity. :)

def factorial(number)
raise NotImplementedError
return 1 if number == 0

Choose a reason for hiding this comment

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

[nit] You should definitely indent all the lines between def factorial(number) and the final end for readability.

end



Choose a reason for hiding this comment

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

[nit] It's good to get in the habit now of deleting lots of empty lines at the end of code files. You'll definitely get nit-picky feedback on these sorts of formatting things on the job.

raise ArgumentError, "Enter an integer"
end
a = 1
b = number

Choose a reason for hiding this comment

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

[nit] I had to run the tests and stare at this to prove to myself that factorial(1) returns the right thing. In other cases I'd say it's duplicative to add && number == 1 to your return 1 if statement up at the top, but in this case I think it might actually benefit readability. Not something you need to change; I only note it to show you how unpredictable "readability" can be as a problem. Humans, am I right?

a = 1
b = number
while a < number
b = b * (number - a)

Choose a reason for hiding this comment

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

a and b aren't particularly descriptive variable names. For b, I'd suggest calling it product -- you're using it to accumulate the overall product of every number between 1 and number. a is a little harder to name, but you could decrement number (i.e. do number -= 1 every loop) in order to not need a at all.

@@ -1,6 +1,54 @@
# Computes factorial of the input number and returns it
# Time complexity: ?
# Space complexity: ?
# Time complexity: Linear or O(n) where n is the number input

Choose a reason for hiding this comment

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

Please also briefly explain why.

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