object Isogram { fun isIsogram(input: String): Boolean { val sanitizedInput = input.toLowerCase().replace("[.!?\\-\\s]".toRegex(), "") val charCounts = sanitizedInput.toList().countBy() return !charCounts.any { it.value > 1 } } } fun Iterable.countBy() : Map = this.countBy({it}) fun Iterable.countBy(transformer: (T) -> M) : Map { val emptyMap = mapOf() return this.fold(emptyMap) {accumulator, item -> val transformedItem = transformer(item) accumulator + Pair(transformedItem, accumulator.getOrElse(transformedItem, {0}) + 1) } }