Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Closures in Swift 2 Building Standard Library Functions Map

There 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
Dotun Ogunsakin
13,475 Points

I 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