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 trialBrook Wolcott
874 PointsHow do I remove an item from an array?
I am working on a challenge asking me to use the removeAtIndex() method to remove the 6th item (index 5) from an array. Since removeAtIndex() has been replaced in Swift 3, I cannot test my code in XCode. However, I have reviewed it about 50 times now and I can't find a problem.
Can anyone tell me when I keep getting a "Bummer" message saying to make sure I remove the 6th item from Index 5?
// Enter your code below
var arrayOfInts = [12, 13, 24, 55, 44, 7]
arrayOfInts.append(77)
arrayOfInts = arrayOfInts + [23]
let value = arrayOfInts[4]
arrayOfInts.removeAtIndex(5)
let discardedValue = (arrayOfInts)
1 Answer
Damien Watson
27,419 PointsHey Brook, the wording is a bit tricky.
It's saying to remove the 6th value and place that value (the 6th you have removed) into the 'discardedValue
'. The return value for '.removeAtIndex()
' is the item removed.
let discardedValue = arrayOfInts.removeAtIndex(5)
Brook Wolcott
874 PointsBrook Wolcott
874 PointsAhh... that makes more sense. Thanks, Damien!
Damien Watson
27,419 PointsDamien Watson
27,419 PointsGlad it helped. :)