Created
November 16, 2019 16:04
-
-
Save jonahaung/c31eea7649cdfa639cbe4013cc11b380 to your computer and use it in GitHub Desktop.
Myanmar Numbers Converter
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
import Foundation | |
protocol MyanmarNumber {} | |
extension MyanmarNumber { | |
func toMyanmarNumber() -> String? { | |
guard let this = self as? NSNumber else { | |
return nil | |
} | |
let value = "\(this)".map { (char) -> Int in | |
let code = Int(UnicodeScalar(String(char))!.value) | |
return (code >= 48 && code <= 57) ? code + 4112 : code | |
}.reduce("") { "\($0)\(String(Character(UnicodeScalar($1)!)))" } | |
return value | |
} | |
} | |
extension Int : MyanmarNumber {} | |
extension Double : MyanmarNumber {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment