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

Please update the last part of the lesson in Code Samples section. array.slice method does NOT actually remove items

Please update the last part of the lesson in Code Samples section. array.slice method does NOT actually remove items from array.

Thanks

2 Answers

rowend rowend
rowend rowend
2,926 Points

Mirshad Oz I understand what you mean...the lesson is about removing elements from array and the slice method is not for that.

Actually, you might've mistaken something.

:point_right:The slice method wasn't designed to remove anything.

It was designed to retrieve all the items from one index to another. Let's pretend I'm in irb:

irb(main):001:0> numbers = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb(main):002:0> one_through_three = numbers.slice(0, 3)
=> [1, 2, 3]
irb(main):003:0> one_through_three
=> [1, 2, 3]
irb(main):004:0> numbers
=> [1, 2, 3, 4, 5]

As you see, the slice method didn't modify the numbers array but did return a value :)

I hope you understand.

Good luck!

~Alex