Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Collections Ruby Arrays Removing Items From Arrays

Nots sure with this one

grocery_list = ["milk", "eggs", "bread", "ice cream", "carrots", "potatoes"] last_item = grocery_list.pop first_item = last_item.shift[0]

array.rb
grocery_list = ["milk", "eggs", "bread", "ice cream", "carrots", "potatoes"]
last_item = grocery_list.pop
first_item = last_item.shift[0]

1 Answer

You are close! Just keep in min that shift is very similar to pop. The only thing shift does differently is that it removes the first item instead of the last item. It returns the first item as well, like the pop method does.

So this means you should call the method on the grocery_list array, not the first_item string. Also, you shouldn't pass in an argument to the shift method; remember shift already knows by default to remove the first element and isn't expecting an index.

I hope this helps :grin:

~Alex

OMG1 Thanks a lot for your time and help. have a great day.

No problem :)

Can you please provide a best answer as well? Thank you! ~Alex