#kotlinDevChallenge – 17

|

Implement extension functions plus and minus to perform vector addition and subtraction.

Task Description:

  1. data class Vector is given with a property coordinates, a list of integers representing the vector’s coordinates.
  2. Implement a function plus for the Vector class to add two vectors. The function should return a new Vector representing the sum.
  3. Implement a function minus for the Vector class to subtract two vectors. The function should return a new Vector representing the difference.
  4. Ensure both functions handle cases where vectors have different dimensions by returning null or an appropriate error message.
  5. Make operator invocations possible:

Example usage:

Vector(listOf(1, 2, 3)) + Vector(listOf(4, 5, 6)) == Vector(listOf(5,7,9)

Vector(listOf(-1, -3)) - Vector(listOf(-2, -2)) == Vector(listOf(1, -1))

Vector(listOf(3, 4, 5)) - Vector(listOf(1, 2)) == null
  1. Fill in the code.
  2. You can copy the code into IntelliJ/Android Studio, but it shouldn’t be necessary.
  3. Click “run” – the green triangle. The code will compile and several tests will be run.
  4. In the logs, you will see “try again” if the solution is incorrect, or “success” and a special code.
  5. Provide this code in the form below along with your email and click “send”.

Join The Android Architect cohort #2

6 weeks cohort course on Architecture and Mobile Devops

✅ Mentor + peer homework review

Learn from Kotlin GDE, Jarosław Michalik: Draw on the expertise of a seasoned Android professional.


high-level design guide for Android Architects


Wow finally something straightforward” ~ Marcin, Senior Android Engineer

  • high-level design overview
  • explanatory video
  • you were probably looking for it for a long time

Read more:

  • #kotlinDevChallenge 2023 summary

    #kotlinDevChallenge 2023 summary

    The KotlinDevChallenge was not just a competition, but a journey of learning, growth, and community engagement. Every participant in this challenge is a winner…

  • #kotlinDevChallenge – 24

    #kotlinDevChallenge – 24

    What do you love most about Kotlin? Productivity increase? Idioms? Or that it isn’t Java? Maybe something else! Share it. It can be short.…

  • #kotlinDevChallenge – 23

    #kotlinDevChallenge – 23

    Challenge checking your generics knowledge 🙂 No long description is necessary. You can select more than one answer. Good luck!