Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit 655e6e0

Browse files
committed
Resolutions
1 parent 36d3c33 commit 655e6e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+200
-100
lines changed

src/i_introduction/_0_Hello_World/n00Start.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@ fun todoTask0(): Nothing = TODO(
2424
references = { task0(); "OK" }
2525
)
2626

27-
fun task0(): String {
28-
return todoTask0()
29-
}
27+
fun task0() = "OK"

src/i_introduction/_10_Object_Expressions/n10ObjectExpressions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ fun todoTask10(): Nothing = TODO(
1818

1919
fun task10(): List<Int> {
2020
val arrayList = arrayListOf(1, 5, 2)
21-
Collections.sort(arrayList, todoTask10())
21+
Collections.sort(arrayList, object : Comparator<Int> {
22+
override fun compare(x: Int, y: Int) = y - x
23+
})
2224
return arrayList
2325
}

src/i_introduction/_11_SAM_Conversions/n11SAMConversions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fun todoTask11(): Nothing = TODO(
1515

1616
fun task11(): List<Int> {
1717
val arrayList = arrayListOf(1, 5, 2)
18-
Collections.sort(arrayList, { x, y -> todoTask11() })
18+
Collections.sort(arrayList, { x, y -> y - x })
1919
return arrayList
2020
}

src/i_introduction/_12_Extensions_On_Collections/n12ExtensionsOnCollections.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ fun todoTask12(): Nothing = TODO(
1717
)
1818

1919
fun task12(): List<Int> {
20-
todoTask12()
21-
return arrayListOf(1, 5, 2)
20+
return arrayListOf(1, 5, 2).sortedDescending()
2221
}
2322

src/i_introduction/_1_Java_To_Kotlin_Converter/n01JavaToKotlinConverter.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,16 @@ fun todoTask1(collection: Collection<Int>): Nothing = TODO(
1414

1515

1616
fun task1(collection: Collection<Int>): String {
17-
todoTask1(collection)
17+
val sb = StringBuilder()
18+
sb.append("{")
19+
val iterator = collection.iterator()
20+
while (iterator.hasNext()) {
21+
val element = iterator.next()
22+
sb.append(element)
23+
if (iterator.hasNext()) {
24+
sb.append(", ")
25+
}
26+
}
27+
sb.append("}")
28+
return sb.toString()
1829
}

src/i_introduction/_2_Named_Arguments/n02NamedArguments.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ fun todoTask2(): Nothing = TODO(
2424
references = { collection: Collection<Int> -> task1(collection); collection.joinToString() })
2525

2626
fun task2(collection: Collection<Int>): String {
27-
todoTask2()
28-
return collection.joinToString()
27+
return collection.joinToString(prefix = "{", postfix = "}")
2928
}

src/i_introduction/_3_Default_Arguments/n03DefaultArguments.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ fun todoTask3(): Nothing = TODO(
1414
documentation = doc2(),
1515
references = { name: String -> JavaCode3().foo(name); foo(name) })
1616

17-
fun foo(name: String): String = todoTask3()
17+
fun foo(name: String, number: Int = 42, toUpperCase: Boolean = false) =
18+
(if (toUpperCase) name.toUpperCase() else name) + number
1819

1920
fun task3(): String {
20-
todoTask3()
21-
// return (foo("a") +
22-
// foo("b", number = 1) +
23-
// foo("c", toUpperCase = true) +
24-
// foo(name = "d", number = 2, toUpperCase = true))
21+
return (foo("a") +
22+
foo("b", number = 1) +
23+
foo("c", toUpperCase = true) +
24+
foo(name = "d", number = 2, toUpperCase = true))
2525
}

src/i_introduction/_4_Lambdas/n04Lambdas.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ fun todoTask4(collection: Collection<Int>): Nothing = TODO(
2222
documentation = doc4(),
2323
references = { JavaCode4().task4(collection) })
2424

25-
fun task4(collection: Collection<Int>): Boolean = todoTask4(collection)
25+
fun task4(collection: Collection<Int>): Boolean = collection.any { it % 2 == 0 }

src/i_introduction/_5_String_Templates/n05StringTemplates.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ fun todoTask5(): Nothing = TODO(
3535
documentation = doc5(),
3636
references = { getPattern(); month })
3737

38-
fun task5(): String = todoTask5()
38+
fun task5(): String = """\d{2} $month \d{4}"""

src/i_introduction/_6_Data_Classes/n06DataClasses.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ fun todoTask6(): Nothing = TODO(
1515
references = { JavaCode6.Person("Alice", 29) }
1616
)
1717

18-
class Person
18+
data class Person(val name: String, val age: Int)
1919

2020
fun task6(): List<Person> {
21-
todoTask6()
22-
return listOf(/*Person("Alice", 29), Person("Bob", 31)*/)
21+
// todoTask6()
22+
return listOf(Person("Alice", 29), Person("Bob", 31))
2323
}
2424

0 commit comments

Comments
 (0)