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 trialLuc Charbonneau
1,789 PointsCan one of the lists have more than one value by the end of the merge loop. Jay Keeps saying "a" value. Incorrect?
At around 3:30 Jay says “The one with a value left will add that value.” shouldn’t he have said “the one with values left will add its values”? To me it looks like one of the lists can have more than one value by the end of the loop.
1 Answer
Michael Hulet
47,913 PointsJay's right here. By the time the while
loop finishes, either left_values
or right_values
will have a singe value left within, and the other one won't. Remember that when the loop began, they both had the same number of values (or potentially one might have 1 more value than the other if values
had an odd number of items). Regardless, the loop goes over both left_values
and right_values
and takes 1 object at a time from each until one of them has no values left. The end result is that the condition will fail and the loop will stop once one of the arrays run out of contents, and the other will be guaranteed to have exactly 1 value left