refactored to use 1 method and commented the code.

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-01-21 09:11:06 -06:00
parent 43a3c456f7
commit 0ad993ca6b

View File

@ -12,11 +12,9 @@ extension String {
/// Non-numeric characters are removed, and formatting is applied based on the length of the string.
/// - Returns: A formatted phone number as a string.
internal func formatUSNumber() -> String {
// format the number
return format(with: "XXX-XXX-XXXX", phone: self)
}
// mask for the phone numver
let mask = "XXX-XXX-XXXX"
internal func format(with mask: String, phone: String) -> String {
let numbers = filter { $0.isNumber }
var result = ""
var index = numbers.startIndex // numbers iterator