-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6249 from juanjoseen/main
Reto #9 - swift
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
Retos/Reto #9 - HETEROGRAMA, ISOGRAMA Y PANGRAMA [Fácil]/swift/juanjoseen.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Foundation | ||
|
||
extension String { | ||
var esHeterograma: Bool { | ||
for (key, value) in conteo() { | ||
if value > 1 { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
var esIsograma: Bool { | ||
var total: Int = -1 | ||
var conteo: [String: Int] = conteo() | ||
for (key, value) in conteo { | ||
if total < 0 { | ||
total = value | ||
} else { | ||
if value != total { | ||
return false | ||
} | ||
} | ||
} | ||
return true | ||
} | ||
|
||
var esPangrama: Bool { | ||
let lower: String = self.lowercased() | ||
for char in Array("abcdefghijklmnopqrstuvwxyz") { | ||
if !lower.contains(where: { $0 == char }) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
private func conteo() -> [String: Int] { | ||
var dic: [String: Int] = [:] | ||
for char in Array(self) { | ||
let key: String = String(char) | ||
var value: Int = dic[key] ?? 0 | ||
dic[key] = value + 1 | ||
} | ||
|
||
return dic | ||
} | ||
} | ||
|
||
print("yuxtaponer".esHeterograma) | ||
print("papa".esIsograma) | ||
print("Benjamín pidió una bebida de kiwi y fresa. Noé, sin vergüenza, la más exquisita champaña del menú.".esPangrama) | ||
|