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 trialRon L
6,463 PointsUsing .drop(2) in Ruby version 2.2.1 drops the first two items (not the last two)
x = ["eggs", "bread", "butter", "water", "milk"] y = x.drop(2) => ["butter", "water", "milk"] y => ["butter", "water", "milk"]
using .drop(2) returns the array with the first two elements removed. It does not create the new variable out of the last two elements of the array as the video states.
2 Answers
Unsubscribed User
11,042 PointsTo clearly explain the drop method, I finally made it like this: array.drop(n) is the same array but without the first n items
Garrett Carver
14,681 PointsYou are right. I think Jason's example array in the video just isn't very clear, since there were 4 items inside and he drops 2 from it. He says "you'll see our variable contains the last two items in the array" but he doesn't explain that it's because the first two were dropped, not because drop returns the last two.