Home > katas > Multiply Kotlin (8kyu)

Multiply Kotlin (8kyu)

Let's start with Multiply kata. I have to solve this one when I signed up for the Codewars account. It is some kind of validation, I guess.

Chek kata on Codewars


The code does not execute properly. Try to figure out why.

We start with this code:

fun multiply(x: double, y: double) => x * y

My first option was:

fun multiply(x: Double, y: Double): Double {
    return x * y

I've change double to Double and add type of output.

Or we can do oneliner. And omit output type.

fun multiply(x: Double, y: Double) = x * y

But I prefer typing output as well, so I chose this one to submit:

fun multiply(x: Double, y: Double): Double = x * y

Let's check others solutions.

We could solve it with lambda function as well. Some people did.

val multiply = { x: Double, y: Double -> x * y }
© 2021, Andrew Losseff