Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
👍 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.
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) |
No description provided.