-
Notifications
You must be signed in to change notification settings - Fork 47
Leaves - Morgan #40
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
base: master
Are you sure you want to change the base?
Leaves - Morgan #40
Conversation
CheezItMan
left a comment
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.
Some good work here. Of course some of the methods are incomplete and not working. Take a look at my comments and let me know if you have questions.
| def factorial(num) | ||
| raise ArgumentError if num < 0 | ||
| return num * factorial(num - 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.
You're missing a base case here.
def factorial(num)
raise ArgumentError, "Cannot accept a number < 0"
return 1 if num <= 1
return num * factorial(num - 1)
end| def reverse(s) | ||
| raise NotImplementedError, "Method not implemented" | ||
| if s.length > 1 then | ||
| ((s[s.length - 1, 1] = s[(s.length - (s.length + 1)), 1]) + reverse_recursive(s.length - 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.
You don't have a reverse_recursive method 🤔
| def reverse_inplace(s) | ||
| raise NotImplementedError, "Method not implemented" | ||
| return s if s.length <= 1 | ||
| reversed_str = reverse(s[1..-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.
You're calling the reverse method in the method above here.
It's also in no way in place.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def nested(s) |
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.
👍 This works, although since you are creating a new array with s[1..s.length-2] your time & space complexities are off.
They should be O(n2)
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def search(array, value, index = 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.
You're never calling this method with another index number, so you don't need this argument.
Alternatively you don't need to create a new array and instead call the method with an increasing index.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def digit_match(n, m) |
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.
👍
No description provided.