Skip to content

Commit b511165

Browse files
author
frubio
committed
Solución Reto mouredev#47 Kotlin
1 parent 01f69ed commit b511165

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/src/main/java/com/mouredev/weeklychallenge2022/Challenge47.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,30 @@ package com.mouredev.weeklychallenge2022
1616
* - Tienes toda la información sobre los retos semanales en
1717
* https://retosdeprogramacion.com/semanales2022.
1818
*
19-
*/
19+
*/
20+
21+
fun main() {
22+
val vocal =
23+
maxRepeatVocal("Enunciado: Crea un función que reciba un texto y retorne la vocal que más veces se repita.")
24+
println("La vocal ${vocal.first} se repite ${vocal.second} veces.")
25+
}
26+
27+
28+
private fun maxRepeatVocal(text: String): Pair<String, Int> {
29+
val repeatVocalMap = mutableMapOf("A" to 0, "E" to 0, "I" to 0, "O" to 0, "U" to 0)
30+
31+
for (i in text.indices) {
32+
when (text.uppercase()[i]) {
33+
'A', 'Á' -> repeatVocalMap["A"]?.let { repeatVocalMap.replace("A", it.plus(1)) }
34+
'E', 'É' -> repeatVocalMap["E"]?.let { repeatVocalMap.replace("E", it.plus(1)) }
35+
'I', 'Í' -> repeatVocalMap["I"]?.let { repeatVocalMap.replace("I", it.plus(1)) }
36+
'O', 'Ó' -> repeatVocalMap["O"]?.let { repeatVocalMap.replace("O", it.plus(1)) }
37+
'U', 'Ú' -> repeatVocalMap["U"]?.let { repeatVocalMap.replace("U", it.plus(1)) }
38+
}
39+
}
40+
41+
return repeatVocalMap.toList()
42+
.sortedBy { (key, value) -> value }
43+
.reversed()[0]
44+
;
45+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Dec 21 19:27:36 CET 2021
1+
#Tue Nov 22 09:15:35 CET 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)