refactored to use 1 method and commented the code.
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
43a3c456f7
commit
0ad993ca6b
@ -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)
|
||||
}
|
||||
|
||||
internal func format(with mask: String, phone: String) -> String {
|
||||
// mask for the phone numver
|
||||
let mask = "XXX-XXX-XXXX"
|
||||
|
||||
let numbers = filter { $0.isNumber }
|
||||
var result = ""
|
||||
var index = numbers.startIndex // numbers iterator
|
||||
@ -35,6 +33,6 @@ extension String {
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user