Skip to content

Conversation

@MariaWissler
Copy link

Sorry is a little late, catching up

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.

You have some issues on nth_from_end, but otherwise you hit the learning goals here. Nice work

Comment on lines 209 to 228
def find_nth_from_end(n)
raise NotImplementedError
#raise NotImplementedError
current = @head
index = 0

while current != nil && index != n
current = current.next
index += 1

if current == nil
return nil
end

new_current = @head
while current.next != nil
current = current.next
new_current = new_current.next
end
return new_current.data
end

Choose a reason for hiding this comment

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

A couple of things:

  1. Your indentation is off here.
  2. You are missing an end
  3. Even beyond that, it's not working because on empty lists or lists shorter than what's given new_current may end up being nil.

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