Skip to content

Instantly share code, notes, and snippets.

@dcampogiani
Created June 1, 2018 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcampogiani/94d321cd80dc6af53ba5e5f100912521 to your computer and use it in GitHub Desktop.
Save dcampogiani/94d321cd80dc6af53ba5e5f100912521 to your computer and use it in GitHub Desktop.
fun fizzBuzz(input: Int, entryList: List<Entry>): String {
val filtered = entryList.filter { input isMultipleOf it.value }
return if (filtered.isEmpty()) {
input.toString()
} else {
filtered.joinToString(separator = "") { it.decorateString }
}
}
infix fun Int.isMultipleOf(other: Int) = this.rem(other) == 0
val entryList = listOf(
Entry(3, "fizz"),
Entry(5, "buzz"),
Entry(7, "pazz"))
data class Entry(val value: Int, val decorateString: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment