Skip to content

Conversation

@morganschuler
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a 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.

Comment on lines +5 to 8
def factorial(num)
raise ArgumentError if num < 0
return num * factorial(num - 1)
end

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

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])

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)

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)

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)

Choose a reason for hiding this comment

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

👍

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