Download a handy 2-page PDF Kotlin Cheat Sheet and Quick Reference!
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6649-kotlin-cheat-sheet-and-quick-reference
Download a handy 2-page PDF Kotlin Cheat Sheet and Quick Reference!
println(15.fizzBuzz()) // Prints fizz when it should print fizzbuzz
Code should be:
fun Int.fizzBuzz(): String {
return when {
this % 15 == 0 -> "fizzbuzz"
this % 3 == 0 -> "fizz"
this % 5 == 0 -> "buzz"
else -> this.toString()
}
}
@accordionguy Do you have any feedback about this? Thank you - much appreciated! :]
You are correct! I donโt know how that one slipped by (I ran all the examples in a โharnessโ project in Android Studio), but apparently it did. Thanks for catching it; Iโm going to see about getting a correction made to the cheat sheet.
โ Joey