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 trialWei Wei
8,201 PointsThere are only 3 elements in the dataStrings array.Why the console on the right shows 4 times after we call the map func
There are only 3 elements in the dataStrings array. Why the console on the right shows 4 times after we call the map function?
Dotun Ogunsakin
13,475 PointsDotun Ogunsakin
13,475 PointsI was curious about that also, then stumbled upon the answer:
The XCode Playground appears to count the total number of operations performed in a line. So, the assignment to the variable counts as an action, and when you add the mapping loop over 3 elements, you get 4 operations on that line.
To make it clear, type the following line into a Playground page:
let a = [1, 2]; a; a; //(3 times)
The 3 operations are: the assignment, 1st variable call, 2nd variable call; all on one line in the Playgrounds page