Created
October 26, 2021 13:06
-
-
Save mmuoDev/8f2e24b6e6bdf665320c7fc88514b919 to your computer and use it in GitHub Desktop.
Return the network provider of a Nigerian phone number
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
func getNetwork(phone string) string { | |
networks := make(map[string][]string) | |
networks["mtn"] = []string{"0803", "0806", "0814", "0810", "0813", "0814", "0816", "0703", "0706", "0903", "0906"} | |
networks["9mobile"] = []string{"0809", "0817", "0818", "0908", "0909"} | |
networks["airtel"] = []string{"0802", "0808", "0812", "0708", "0701", "0902", "0901", "0907"} | |
networks["glo"] = []string{"0805", "0807", "0811", "0815", "0705", "0905"} | |
for k, prefixes := range networks { | |
for _, p := range prefixes { | |
if phone[:4] == p { | |
return k | |
} | |
} | |
} | |
return "N/A" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment