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 trialUnsubscribed User
355 PointsRemoving item from list and assigning back as a constant or variable
At 6.47, Amit says that by using the let item (2)=todo.removeAtIndex (1), you can assign the last value as a constant or variable.
Why would this be important, any specific reasons?
Thanks Faizal
1 Answer
Stephen Whitfield
16,771 PointsIt's useful for a plethora of reasons... reasons I couldn't exactly tell you unless you gave me the context. For example, let's say you wanted to store that value in an array or dictionary. It would be convenient/code-hygenic for you to create a temporary variable and store that value there. What if you also needed it later in the code? You have it assigned to a variable now so you can grab it whenever you need it.
X. Szuh
2,486 PointsX. Szuh
2,486 PointsIn the to do list context, once the task is complete it should be removed and perhaps you want to construct another array or list of completed items for display perhaps?