Homework 3: Complex Kotlin
Due April 10
Last updated
Due April 10
Last updated
In this homework assignment, you task is to ensure that the Kotlin code you will be writing will pass all of our given unit tests.
The benefit of completing this assignment is that you will learn how to use the Terminal to write commands to execute a Kotlin script file. At some point in your career as a developer, you'll encounter the command line interface (CLI) as part of your development workflow. Completing this assignment is a good chance to become more comfortable working in such environment.
Always refer to the Assignment section for any changes to the assignment.
In order to run your test script, you must ensure that the following items have been completed:
You can do so by executing the command kotlinc -script main.kts
in your Terminal.
Kotlin functions can be stored in variables and data structures or even passed down as arguments. This feature is known as function.
Here's an example of a higher-order function:
To learn more about higher-order functions and lambdas, read .
Here's a simple lambda expression:
You can also simplify your code like so:
The special thing about higher-order functions and lambda expressions is that you can use things like .map {}
and .filter {}
. These higher-order functions will be very useful for your homework assignment.
You might find that knowing the difference between listOf(12..20)
and listOf(12,13,14,15,16,17,18,19,20)
and just plain (12..20)
can be very useful.
repeat(x)
function might come in handy whenever you want to repeat, say, a string!
Wikipedia also , and does so very well. I encourage you to have a go at it too.
To learn more about higher-order functions and lambdas, read .
Feel free to check out this to learn more about how these types of functions work.
and the function!
Ask yourself ?