Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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