-
Exercism - Acronym(with.Kotlin)문제풀이/Exercism 2019. 8. 19. 00:37반응형
[문제]
Convert a phrase to its acronym.
Techies love their TLA (Three Letter Acronyms)!
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
[Solution1]
object Acronym { fun generate(phrase : String) : String{ val strList = phrase.replace("-", " ").split(" ").filter { it.isNotEmpty() } val expected = CharArray(strList.size) strList.mapIndexed { index, s -> expected[index] = s.first() } return expected.joinToString("").toUpperCase() } }
생각이 나는 대로 풀어서 작성하였습니다.
[Solution2]
object Acronym { fun generate(phrase : String) : String = phrase.replace("-", " ") .split(" ") .filter { it.isNotEmpty() } .map { it.first() } .joinToString("") .toUpperCase() }
풀어서 작성한것을 정리한 코드입니다.
반응형'문제풀이 > Exercism' 카테고리의 다른 글
Exercism - Diamond(with.Kotlin) (0) 2019.08.27 Exercism - Largest Series Product (With.Kotlin) (0) 2019.08.21 Exercism - Luhn(with.Kotlin) (0) 2019.08.19 Exercism - Perfect Numbers(with.Kotlin) (0) 2019.08.17 Exercism - Difference Of Squares(with.Kotlin) (0) 2019.08.06 Exercism - Scrabble Score (With.Kotlin) (0) 2019.07.30 Exercism - Space Age (With.Kotlin) (0) 2019.07.26 Exercism - Gigasecond(With.Kotlin) (0) 2019.07.23