Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package syntax.functionParameterConfusion

val items = listOf("a", "b", "c")

println(items.joinToString { " + " })

// What will the output be?
// a) "a + b + c"
// b) "a b c"
// c) "a, b, c"
// d) None of the above
9 changes: 9 additions & 0 deletions src/syntax/functionParameterConfusion/Rationale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Correct answer: **d) None of the above** - the created string is actually `" + , + , + "`

`joinToString` has a default argument for every parameter, including the _separator_. The code uses curly brackets
(`{ ... }`) which therefore represents the _transform_ function, transforming every element. The parameter (`it`) of
the transform function was omitted.

The lesson from this: Pay attention to the difference between parentheses and curly brackets and verify that you are
passing a value for the correct parameter. Also be careful when using suggestions from the IDE, here IntelliJ IDEA
would have suggested the variant with _transform_ function first.
2 changes: 1 addition & 1 deletion src/syntax/gameOfLife/Rationale.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Correct answer: **b) 3**

* Languges without semicolons need to make decisions when a statement ends
* Languages without semicolons need to make decisions when a statement ends
* Lines starting with '+' can be interpreted as starting with unary '+'
* Groovy has the same problem, but JavaScript hasn't
* Fix by keeping '+' on the previous line
Expand Down